Browse Source

Name is optional, generated from the repository location

Samuel W. Flint 4 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
                   help: The type of repository
                   required: true
                   required: true
               - name:
               - name:
-                  index: 2
+                  long: name
+                  short: n
                   value_name: REPO_NAME
                   value_name: REPO_NAME
                   help: The name of the repository
                   help: The name of the repository
-                  required: true
               - options:
               - options:
-                  index: 3
+                  index: 2
                   value_name: OPTION
                   value_name: OPTION
                   help: Type-specific options, in form "name=value"
                   help: Type-specific options, in form "name=value"
                   multiple: true
                   multiple: true

+ 7 - 3
src/main.rs

@@ -33,14 +33,18 @@ fn main() {
             match matches.subcommand_name() {
             match matches.subcommand_name() {
                 Some("register") => if let Some(matches) = matches.subcommand_matches("register") {
                 Some("register") => if let Some(matches) = matches.subcommand_matches("register") {
                     let type_name = matches.value_of("type").unwrap().to_string();
                     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 option_strings_in: Vec<&str> = matches.values_of("options").unwrap().collect();
                     let mut option_strings: Vec<String> = Vec::new();
                     let mut option_strings: Vec<String> = Vec::new();
                     for str_thing in option_strings_in {
                     for str_thing in option_strings_in {
                         option_strings.push(str_thing.to_string())
                         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") {
                 Some("config") => if let Some(matches) = matches.subcommand_matches("config") {
                     let name = matches.value_of("name").unwrap().to_string();
                     let name = matches.value_of("name").unwrap().to_string();