movey_cli_commands/
lib.rs

1use clap::{App, AppSettings};
2use clap::{crate_version, crate_description, crate_authors};
3
4use core::commands;
5use utils::error::Result;
6
7mod base;
8use base::movey_login::MoveyLogin;
9use base::movey_upload::MoveyUpload;
10use base::move_package_resolver::MovePackageResolver;
11
12/// Match commands
13pub fn cli_match() -> Result<()> {
14    // Get matches
15    let cli_matches = cli_config()?;
16
17    // Merge clap config file if the value is set
18    // AppConfig::merge_config(cli_matches.value_of("config"))?;
19
20    // Matches Commands or display help
21    match cli_matches.subcommand_name() {
22        Some("hazard") => {
23            commands::hazard()?;
24        }
25        Some("error") => {
26            commands::simulate_error()?;
27        }
28        Some("config") => {
29            commands::config()?;
30        }
31        Some("login") => {
32            MoveyLogin::execute()?;
33        },
34        Some("upload") => {
35            MoveyUpload::execute(None)?
36        }
37        Some("move-package-resolver") => {
38            MovePackageResolver::execute()?
39        }
40        _ => {
41            // Arguments are required by default (in Clap)
42            // This section should never execute and thus
43            // should probably be logged in case it executed.
44        }
45    }
46    Ok(())
47}
48
49/// Configure Clap
50/// This function will configure clap and match arguments
51pub fn cli_config() -> Result<clap::ArgMatches> {
52    let cli_app = App::new("movey-cli")
53        .setting(AppSettings::ArgRequiredElseHelp)
54        .version(crate_version!())
55        .about(crate_description!())
56        .author(crate_authors!("\n"))
57        .subcommand(App::new("login").about("Login to Movey"))
58        .subcommand(App::new("upload").about("Upload to Movey"))
59        .subcommand(App::new("move-package-resolver").about("Parse dependencies from Move.toml"));
60    // Get matches
61    let cli_matches = cli_app.get_matches();
62
63    Ok(cli_matches)
64}