difftreelog
refactor replace clap with structopt
in: trunk
6 files changed
Cargo.lockdiffbeforeafterboth327 "atty",327 "atty",328 "bitflags",328 "bitflags",329 "strsim 0.8.0",329 "strsim 0.8.0",330 "textwrap 0.11.0",330 "textwrap",331 "unicode-width",331 "unicode-width",332 "vec_map",332 "vec_map",333]333]334335[[package]]336name = "clap"337version = "3.0.0-beta.2"338source = "registry+https://github.com/rust-lang/crates.io-index"339checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"340dependencies = [341 "atty",342 "bitflags",343 "clap_derive",344 "indexmap",345 "lazy_static",346 "os_str_bytes",347 "strsim 0.10.0",348 "termcolor",349 "textwrap 0.12.1",350 "unicode-width",351 "vec_map",352]353354[[package]]355name = "clap_derive"356version = "3.0.0-beta.2"357source = "registry+https://github.com/rust-lang/crates.io-index"358checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"359dependencies = [360 "heck",361 "proc-macro-error",362 "proc-macro2",363 "quote",364 "syn",365]366334367[[package]]335[[package]]368name = "cookie-factory"336name = "cookie-factory"478 "anyhow",446 "anyhow",479 "base64",447 "base64",480 "chrono",448 "chrono",481 "clap 3.0.0-beta.2",482 "env_logger",449 "env_logger",483 "hostname",450 "hostname",484 "log",451 "log",487 "peg",454 "peg",488 "serde",455 "serde",489 "serde_json",456 "serde_json",457 "structopt",490 "tempfile",458 "tempfile",491 "time 0.3.2",459 "time 0.3.2",492 "z85",460 "z85",596 "wasi 0.10.2+wasi-snapshot-preview1",564 "wasi 0.10.2+wasi-snapshot-preview1",597]565]598599[[package]]600name = "hashbrown"601version = "0.9.1"602source = "registry+https://github.com/rust-lang/crates.io-index"603checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"604566605[[package]]567[[package]]606name = "heck"568name = "heck"725 "syn",687 "syn",726]688]727728[[package]]729name = "indexmap"730version = "1.6.0"731source = "registry+https://github.com/rust-lang/crates.io-index"732checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"733dependencies = [734 "autocfg 1.0.1",735 "hashbrown",736]737689738[[package]]690[[package]]739name = "instant"691name = "instant"954source = "registry+https://github.com/rust-lang/crates.io-index"906source = "registry+https://github.com/rust-lang/crates.io-index"955checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"907checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"956957[[package]]958name = "os_str_bytes"959version = "2.3.2"960source = "registry+https://github.com/rust-lang/crates.io-index"961checksum = "2ac6fe3538f701e339953a3ebbe4f39941aababa8a3f6964635b24ab526daeac"962908963[[package]]909[[package]]964name = "ouroboros"910name = "ouroboros"115411001155[[package]]1101[[package]]1156name = "rand"1102name = "rand"1157version = "0.8.3"1103version = "0.8.4"1158source = "registry+https://github.com/rust-lang/crates.io-index"1104source = "registry+https://github.com/rust-lang/crates.io-index"1159checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"1105checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"1160dependencies = [1106dependencies = [1161 "libc",1107 "libc",1162 "rand_chacha 0.3.0",1108 "rand_chacha 0.3.0",1458source = "registry+https://github.com/rust-lang/crates.io-index"1404source = "registry+https://github.com/rust-lang/crates.io-index"1459checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa"1405checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa"1460dependencies = [1406dependencies = [1461 "clap 2.33.3",1407 "clap",1462 "lazy_static",1408 "lazy_static",1463 "structopt-derive",1409 "structopt-derive",1464]1410]1519dependencies = [1465dependencies = [1520 "cfg-if",1466 "cfg-if",1521 "libc",1467 "libc",1522 "rand 0.8.3",1468 "rand 0.8.4",1523 "redox_syscall",1469 "redox_syscall",1524 "remove_dir_all",1470 "remove_dir_all",1525 "winapi",1471 "winapi",1543 "unicode-width",1489 "unicode-width",1544]1490]15451546[[package]]1547name = "textwrap"1548version = "0.12.1"1549source = "registry+https://github.com/rust-lang/crates.io-index"1550checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"1551dependencies = [1552 "unicode-width",1553]155414911555[[package]]1492[[package]]1556name = "thiserror"1493name = "thiserror"Cargo.tomldiffbeforeafterboth778[dependencies]8[dependencies]9anyhow = "1.0"9anyhow = "1.0"10clap = { version = "3.0.0-beta.2", features = ["derive", "suggestions", "color"] }11log = "0.4.14"10log = "0.4.14"12env_logger = "0.9.0"11env_logger = "0.9.0"13serde = { version = "1.0", features = ["derive"] }12serde = { version = "1.0", features = ["derive"] }23base64 = "0.13.0"22base64 = "0.13.0"24chrono = { version = "0.4.19", features = ["serde"] }23chrono = { version = "0.4.19", features = ["serde"] }25z85 = "3.0.3"24z85 = "3.0.3"25structopt = "0.3.23"262627[workspace]27[workspace]28members = ["crates/nixlike", "cmds/install-secrets"]28members = ["crates/nixlike", "cmds/install-secrets"]src/cmds/build_systems.rsdiffbeforeafterboth223use crate::{command::CommandExt, host::Config, nix::SYSTEMS_ATTRIBUTE};3use crate::{command::CommandExt, host::Config, nix::SYSTEMS_ATTRIBUTE};4use anyhow::Result;4use anyhow::Result;5use clap::Clap;5use log::info;6use log::info;6use structopt::StructOpt;778#[derive(Clap)]8#[derive(StructOpt)]9#[clap(group = clap::ArgGroup::new("target"))]10pub struct BuildSystems {9pub struct BuildSystems {11 /// --builders arg for nix10 /// --builders arg for nix12 #[clap(long)]11 #[structopt(long)]13 builders: Option<String>,12 builders: Option<String>,14 /// Jobs to run locally13 /// Jobs to run locally15 #[clap(long)]14 #[structopt(long)]16 jobs: Option<usize>,15 jobs: Option<usize>,17 /// Do not continue on error16 /// Do not continue on error18 #[clap(long)]17 #[structopt(long)]19 fail_fast: bool,18 fail_fast: bool,20 #[clap(long)]19 #[structopt(long)]21 privileged_build: bool,20 privileged_build: bool,22 #[clap(subcommand)]21 #[structopt(subcommand)]23 subcommand: Option<Subcommand>,22 subcommand: Option<Subcommand>,24}23}252426#[derive(Clap)]25#[derive(StructOpt)]27enum Subcommand {26enum Subcommand {28 /// Switch to built system until reboot27 /// Switch to built system until reboot29 Test,28 Test,src/cmds/secrets/mod.rsdiffbeforeafterboth1use crate::{fleetdata::FleetSecret, host::Config};1use crate::{fleetdata::FleetSecret, host::Config};2use anyhow::{bail, Result};2use anyhow::{bail, Result};3use clap::Clap;4use std::io::{self, Cursor, Read};3use std::io::{self, Cursor, Read};4use structopt::StructOpt;556#[derive(Clap)]6#[derive(StructOpt)]7pub enum Secrets {7pub enum Secrets {8 /// Force load keys for all defined hosts8 /// Force load keys for all defined hosts9 ForceKeys,9 ForceKeys,14 /// Secret owners14 /// Secret owners15 machines: Vec<String>,15 machines: Vec<String>,16 /// Override secret if already present16 /// Override secret if already present17 #[clap(long)]17 #[structopt(long)]18 force: bool,18 force: bool,19 #[clap(long)]19 #[structopt(long)]20 public: Option<String>,20 public: Option<String>,21 },21 },22}22}src/host.rsdiffbeforeafterboth9};9};101011use anyhow::Result;11use anyhow::Result;12use clap::Clap;12use structopt::clap::ArgGroup;13use structopt::StructOpt;131414use crate::{command::CommandExt, fleetdata::FleetData};15use crate::{command::CommandExt, fleetdata::FleetData};1516102 }103 }103}104}104105105#[derive(Clap, Clone)]106#[derive(StructOpt, Clone)]106#[clap(group = clap::ArgGroup::new("target_hosts"))]107#[structopt(group = ArgGroup::with_name("target_hosts"))]107pub struct FleetOpts {108pub struct FleetOpts {108 /// All hosts except those would be skipped109 /// All hosts except those would be skipped109 #[clap(long, number_of_values = 1, group = "target_hosts")]110 #[structopt(long, number_of_values = 1, group = "target_hosts")]110 only: Vec<String>,111 only: Vec<String>,111112112 /// Hosts to skip113 /// Hosts to skip113 #[clap(long, number_of_values = 1, group = "target_hosts")]114 #[structopt(long, number_of_values = 1, group = "target_hosts")]114 skip: Vec<String>,115 skip: Vec<String>,115116116 /// Host, which should be threaten as current machine117 /// Host, which should be threaten as current machine117 #[clap(long)]118 #[structopt(long)]118 pub localhost: Option<String>,119 pub localhost: Option<String>,119}120}120121src/main.rsdiffbeforeafterboth8mod fleetdata;8mod fleetdata;9910use anyhow::Result;10use anyhow::Result;11use clap::Clap;11use structopt::StructOpt;121213use cmds::{build_systems::BuildSystems, secrets::Secrets};13use cmds::{build_systems::BuildSystems, secrets::Secrets};14use host::{Config, FleetOpts};14use host::{Config, FleetOpts};151516#[derive(Clap)]16#[derive(StructOpt)]17#[clap(version = "1.0", author = "CertainLach <iam@lach.pw>")]17#[structopt(version = "1.0", author = "CertainLach <iam@lach.pw>")]18enum Opts {18enum Opts {19 /// Prepare systems for deployments19 /// Prepare systems for deployments20 BuildSystems(BuildSystems),20 BuildSystems(BuildSystems),21 /// Secret management21 /// Secret management22 Secrets(Secrets),22 Secrets(Secrets),23}23}242425#[derive(Clap)]25#[derive(StructOpt)]26struct RootOpts {26struct RootOpts {27 #[clap(flatten)]27 #[structopt(flatten)]28 fleet_opts: FleetOpts,28 fleet_opts: FleetOpts,29 #[clap(subcommand)]29 #[structopt(subcommand)]30 command: Opts,30 command: Opts,31}31}323242 env_logger::Builder::new()42 env_logger::Builder::new()43 .filter_level(log::LevelFilter::Info)43 .filter_level(log::LevelFilter::Info)44 .init();44 .init();45 let opts = RootOpts::parse();45 let opts = RootOpts::from_args();46 let config = opts.fleet_opts.build()?;46 let config = opts.fleet_opts.build()?;474748 match run_command(&config, opts.command) {48 match run_command(&config, opts.command) {