rust/rhg/src/main.rs
changeset 46553 1ecaf09d9964
parent 46552 184e46550dc8
child 46554 95d37db31479
equal deleted inserted replaced
46552:184e46550dc8 46553:1ecaf09d9964
     1 extern crate log;
     1 extern crate log;
     2 use clap::App;
     2 use clap::App;
     3 use clap::AppSettings;
     3 use clap::AppSettings;
     4 use clap::Arg;
       
     5 use clap::ArgGroup;
       
     6 use clap::ArgMatches;
     4 use clap::ArgMatches;
     7 use clap::SubCommand;
       
     8 use format_bytes::format_bytes;
     5 use format_bytes::format_bytes;
     9 
     6 
    10 mod commands;
     7 mod commands;
    11 mod error;
     8 mod error;
    12 mod exitcode;
     9 mod exitcode;
    18     let app = App::new("rhg")
    15     let app = App::new("rhg")
    19         .setting(AppSettings::AllowInvalidUtf8)
    16         .setting(AppSettings::AllowInvalidUtf8)
    20         .setting(AppSettings::SubcommandRequired)
    17         .setting(AppSettings::SubcommandRequired)
    21         .setting(AppSettings::VersionlessSubcommands)
    18         .setting(AppSettings::VersionlessSubcommands)
    22         .version("0.0.1")
    19         .version("0.0.1")
    23         .subcommand(
    20         .subcommand(commands::root::args())
    24             SubCommand::with_name("root").about(commands::root::HELP_TEXT),
    21         .subcommand(commands::files::args())
    25         )
    22         .subcommand(commands::cat::args())
    26         .subcommand(
    23         .subcommand(commands::debugdata::args())
    27             SubCommand::with_name("files")
    24         .subcommand(commands::debugrequirements::args());
    28                 .arg(
       
    29                     Arg::with_name("rev")
       
    30                         .help("search the repository as it is in REV")
       
    31                         .short("-r")
       
    32                         .long("--revision")
       
    33                         .value_name("REV")
       
    34                         .takes_value(true),
       
    35                 )
       
    36                 .about(commands::files::HELP_TEXT),
       
    37         )
       
    38         .subcommand(
       
    39             SubCommand::with_name("cat")
       
    40                 .arg(
       
    41                     Arg::with_name("rev")
       
    42                         .help("search the repository as it is in REV")
       
    43                         .short("-r")
       
    44                         .long("--revision")
       
    45                         .value_name("REV")
       
    46                         .takes_value(true),
       
    47                 )
       
    48                 .arg(
       
    49                     clap::Arg::with_name("files")
       
    50                         .required(true)
       
    51                         .multiple(true)
       
    52                         .empty_values(false)
       
    53                         .value_name("FILE")
       
    54                         .help("Activity to start: activity@category"),
       
    55                 )
       
    56                 .about(commands::cat::HELP_TEXT),
       
    57         )
       
    58         .subcommand(
       
    59             SubCommand::with_name("debugdata")
       
    60                 .about(commands::debugdata::HELP_TEXT)
       
    61                 .arg(
       
    62                     Arg::with_name("changelog")
       
    63                         .help("open changelog")
       
    64                         .short("-c")
       
    65                         .long("--changelog"),
       
    66                 )
       
    67                 .arg(
       
    68                     Arg::with_name("manifest")
       
    69                         .help("open manifest")
       
    70                         .short("-m")
       
    71                         .long("--manifest"),
       
    72                 )
       
    73                 .group(
       
    74                     ArgGroup::with_name("")
       
    75                         .args(&["changelog", "manifest"])
       
    76                         .required(true),
       
    77                 )
       
    78                 .arg(
       
    79                     Arg::with_name("rev")
       
    80                         .help("revision")
       
    81                         .required(true)
       
    82                         .value_name("REV"),
       
    83                 ),
       
    84         )
       
    85         .subcommand(
       
    86             SubCommand::with_name("debugrequirements")
       
    87                 .about(commands::debugrequirements::HELP_TEXT),
       
    88         );
       
    89 
    25 
    90     let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
    26     let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
    91         let _ = ui::Ui::new().writeln_stderr_str(&err.message);
    27         let _ = ui::Ui::new().writeln_stderr_str(&err.message);
    92         std::process::exit(exitcode::UNIMPLEMENTED)
    28         std::process::exit(exitcode::UNIMPLEMENTED)
    93     });
    29     });