Browse Source

Name is optional, generated from the repository location

Samuel W. Flint 3 years ago
parent
commit
c5e483aba4
2 changed files with 10 additions and 6 deletions
  1. 3 3
      src/cli.yml
  2. 7 3
      src/main.rs

+ 3 - 3
src/cli.yml

@@ -46,12 +46,12 @@ subcommands:
                   help: The type of repository
                   required: true
               - name:
-                  index: 2
+                  long: name
+                  short: n
                   value_name: REPO_NAME
                   help: The name of the repository
-                  required: true
               - options:
-                  index: 3
+                  index: 2
                   value_name: OPTION
                   help: Type-specific options, in form "name=value"
                   multiple: true

+ 7 - 3
src/main.rs

@@ -33,14 +33,18 @@ fn main() {
             match matches.subcommand_name() {
                 Some("register") => if let Some(matches) = matches.subcommand_matches("register") {
                     let type_name = matches.value_of("type").unwrap().to_string();
-                    let name = matches.value_of("name").unwrap().to_string();
+                    let location = env::current_dir().unwrap();
+                    let location_string = location.to_str().unwrap().to_string();
+                    let name = match matches.value_of("name") {
+                        Some(string) => string.to_string(),
+                        None => location.file_name().unwrap().to_str().unwrap().to_string()
+                    };
                     let option_strings_in: Vec<&str> = matches.values_of("options").unwrap().collect();
                     let mut option_strings: Vec<String> = Vec::new();
                     for str_thing in option_strings_in {
                         option_strings.push(str_thing.to_string())
                     }
-                    let location = env::current_dir().unwrap().to_str().unwrap().to_string();
-                    repository::register(&mut configuration, &name, location, type_name, option_strings);
+                    repository::register(&mut configuration, &name, location_string, type_name, option_strings);
                 },
                 Some("config") => if let Some(matches) = matches.subcommand_matches("config") {
                     let name = matches.value_of("name").unwrap().to_string();