Skip to content

Commit

Permalink
Merge pull request #3228 from stmcginnis/clapclapclap
Browse files Browse the repository at this point in the history
Update clap and remove use of structopt in tools
  • Loading branch information
stmcginnis authored Jul 6, 2023
2 parents 99ad494 + 9905ffc commit 386bba7
Show file tree
Hide file tree
Showing 28 changed files with 399 additions and 338 deletions.
263 changes: 170 additions & 93 deletions tools/Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tools/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ skip = [
]

skip-tree = [
# structopt pulls in an older version of clap
{ name = "structopt", version = "0.3.26" },

# windows-sys is not a direct dependency. mio and schannel
# are using different versions of windows-sys. we skip the
# dependency tree because windows-sys has many sub-crates
Expand All @@ -86,6 +83,9 @@ skip-tree = [
# TestSys uses a newer version of base64 and serde_yaml
{ name = "testsys-model", version = "=0.0.8" },
{ name = "bottlerocket-types", version = "=0.0.8" },

# generate-readme uses an old version of clap and other dependencies
{ name = "generate-readme", version = "0.1.0" }
]

[sources]
Expand Down
3 changes: 1 addition & 2 deletions tools/infrasys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false

[dependencies]
async-trait = "0.1"
clap = "3"
clap = { version = "4", features = ["derive"] }
hex = "0.4"
log = "0.4"
pubsys-config = { path = "../pubsys-config/", version = "0.1" }
Expand All @@ -22,7 +22,6 @@ sha2 = "0.10"
shell-words = "1"
simplelog = "0.12"
snafu = "0.7"
structopt = { version = "0.3", default-features = false }
tokio = { version = "1", default-features = false, features = ["macros", "rt-multi-thread"] }
toml = "0.5"
url = "2"
Expand Down
22 changes: 10 additions & 12 deletions tools/infrasys/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod s3;
mod shared;

use aws_sdk_cloudformation::Region;
use clap::Parser;
use error::Result;
use log::{error, info};
use pubsys_config::{InfraConfig, RepoConfig, S3Config, SigningKeyConfig};
Expand All @@ -16,35 +17,32 @@ use std::collections::HashMap;
use std::num::NonZeroUsize;
use std::path::{Path, PathBuf};
use std::{fs, process};
use structopt::{clap, StructOpt};
use tokio::runtime::Runtime;
use url::Url;

// =^..^= =^..^= =^..^= SUB-COMMAND STRUCTS =^..^= =^..^= =^..^=

#[derive(Debug, StructOpt)]
#[structopt(setting = clap::AppSettings::DeriveDisplayOrder)]
#[derive(Debug, Parser)]
struct Args {
#[structopt(global = true, long, default_value = "INFO")]
#[arg(global = true, long, default_value = "INFO")]
log_level: LevelFilter,

// Path to Infra.toml (NOTE: must be specified before subcommand)
#[structopt(long, parse(from_os_str))]
// Path to Infra.toml (NOTE: must be specified before subcommand)
#[arg(long)]
infra_config_path: PathBuf,

#[structopt(subcommand)]
#[command(subcommand)]
subcommand: SubCommand,
}

#[derive(Debug, StructOpt)]
#[structopt(setting = clap::AppSettings::DeriveDisplayOrder)]
#[derive(Debug, Parser)]
struct CreateInfraArgs {
/// Path to the root.json file.
#[structopt(long)]
#[arg(long)]
root_role_path: PathBuf,
}

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
enum SubCommand {
/// Creates infrastructure specified in the Infra.toml file.
CreateInfra(CreateInfraArgs),
Expand All @@ -61,7 +59,7 @@ fn main() {

fn run() -> Result<()> {
// Parse and store the args passed to the program
let args = Args::from_args();
let args = Args::parse();

match args.log_level {
// Set log level for AWS SDK to error to reduce verbosity.
Expand Down
4 changes: 2 additions & 2 deletions tools/infrasys/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use aws_sdk_cloudformation::model::{Output, Parameter};
use aws_sdk_cloudformation::Client as CloudFormationClient;
use clap::Parser;
use log::info;
use snafu::{ensure, OptionExt, ResultExt};
use std::{env, thread, time};
use structopt::StructOpt;

use super::{error, Result};

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub enum KeyRole {
Root,
Publication,
Expand Down
2 changes: 1 addition & 1 deletion tools/pubsys-setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
publish = false

[dependencies]
clap = { version = "4", features = ["derive"] }
hex = "0.4"
log = "0.4"
pubsys-config = { path = "../pubsys-config/", version = "0.1" }
Expand All @@ -15,7 +16,6 @@ sha2 = "0.10"
shell-words = "1"
simplelog = "0.12"
snafu = "0.7"
structopt = { version = "0.3", default-features = false }
tempfile = "3"
toml = "0.5"
url = { version = "2", features = ["serde"] }
19 changes: 10 additions & 9 deletions tools/pubsys-setup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ the repos you use to update them. Specifically, it can create a new key and rol
existing role.
*/

use clap::Parser;
use log::{debug, info, trace, warn};
use pubsys_config::InfraConfig;
use sha2::{Digest, Sha512};
Expand All @@ -14,33 +15,33 @@ use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
use std::process::{self, Command};
use structopt::StructOpt;
use tempfile::NamedTempFile;
use url::Url;

/// Helps you get started with credentials to make Bottlerocket images and repos.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Args {
#[structopt(global = true, long, default_value = "INFO")]
#[arg(global = true, long, default_value = "INFO")]
/// How much detail to log; from least to most: ERROR, WARN, INFO, DEBUG, TRACE
log_level: LevelFilter,

#[structopt(long, parse(from_os_str))]
#[arg(long)]
/// Path to Infra.toml
infra_config_path: PathBuf,

#[structopt(long)]
#[arg(long)]
/// Use this named repo infrastructure from Infra.toml
repo: String,

#[structopt(long, parse(from_os_str))]
#[arg(long)]
/// Path to root.json
root_role_path: PathBuf,
#[structopt(long, parse(from_os_str))]

#[arg(long)]
/// If we have to generate a local key, store it here
default_key_path: PathBuf,

#[structopt(long)]
#[arg(long)]
/// Allow setup to continue if we have a root role but no key for it
allow_missing_key: bool,
}
Expand Down Expand Up @@ -71,7 +72,7 @@ macro_rules! tuftool {
/// Main entry point for tuftool setup.
fn run() -> Result<()> {
// Parse and store the args passed to the program
let args = Args::from_args();
let args = Args::parse();

// SimpleLogger will send errors to stderr and anything less to stdout.
SimpleLogger::init(args.log_level, LogConfig::default()).context(error::LoggerSnafu)?;
Expand Down
3 changes: 1 addition & 2 deletions tools/pubsys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ aws-smithy-types = "0.54"
aws-types = "0.54"
buildsys = { path = "../buildsys", version = "0.1" }
chrono = { version = "0.4", default-features = false, features = ["std", "clock"] }
clap = "3"
clap = { version = "4", features = ["derive"] }
coldsnap = { version = "0.5", default-features = false, features = ["aws-sdk-rust-rustls"] }
duct = "0.13"
futures = "0.3"
Expand All @@ -41,7 +41,6 @@ serde_json = "1"
serde_plain = "1"
simplelog = "0.12"
snafu = "0.7"
structopt = { version = "0.3", default-features = false }
tabled = "0.10"
tempfile = "3"
tinytemplate = "1"
Expand Down
23 changes: 11 additions & 12 deletions tools/pubsys/src/aws/ami/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use aws_sdk_ec2::{Client as Ec2Client, Region};
use aws_sdk_sts::error::GetCallerIdentityError;
use aws_sdk_sts::output::GetCallerIdentityOutput;
use aws_sdk_sts::Client as StsClient;
use clap::Parser;
use futures::future::{join, lazy, ready, FutureExt};
use futures::stream::{self, StreamExt};
use log::{error, info, trace, warn};
Expand All @@ -30,49 +31,47 @@ use serde::{Deserialize, Serialize};
use snafu::{ensure, OptionExt, ResultExt};
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use structopt::{clap, StructOpt};
use wait::wait_for_ami;

const WARN_SEPARATOR: &str = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";

/// Builds Bottlerocket AMIs using latest build artifacts
#[derive(Debug, StructOpt)]
#[structopt(setting = clap::AppSettings::DeriveDisplayOrder)]
#[derive(Debug, Parser)]
pub(crate) struct AmiArgs {
/// Path to the image containing the os volume
#[structopt(short = "o", long, parse(from_os_str))]
#[arg(short = 'o', long)]
os_image: PathBuf,

/// Path to the image containing the data volume
#[structopt(short = "d", long, parse(from_os_str))]
#[arg(short = 'd', long)]
data_image: Option<PathBuf>,

/// Path to the variant manifest
#[structopt(short = "v", long, parse(from_os_str))]
#[arg(short = 'v', long)]
variant_manifest: PathBuf,

/// The architecture of the machine image
#[structopt(short = "a", long, parse(try_from_str = parse_arch))]
#[arg(short = 'a', long, value_parser = parse_arch)]
arch: ArchitectureValues,

/// The desired AMI name
#[structopt(short = "n", long)]
#[arg(short = 'n', long)]
name: String,

/// The desired AMI description
#[structopt(long)]
#[arg(long)]
description: Option<String>,

/// Don't display progress bars
#[structopt(long)]
#[arg(long)]
no_progress: bool,

/// Regions where you want the AMI, the first will be used as the base for copying
#[structopt(long, use_delimiter = true)]
#[arg(long, value_delimiter = ',')]
regions: Vec<String>,

/// If specified, save created regional AMI IDs in JSON at this path.
#[structopt(long)]
#[arg(long)]
ami_output: Option<PathBuf>,
}

Expand Down
19 changes: 9 additions & 10 deletions tools/pubsys/src/aws/promote_ssm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,43 @@ use crate::aws::{parse_arch, region_from_string};
use crate::Args;
use aws_sdk_ec2::model::ArchitectureValues;
use aws_sdk_ssm::{Client as SsmClient, Region};
use clap::Parser;
use log::{info, trace};
use pubsys_config::InfraConfig;
use snafu::{ensure, ResultExt};
use std::collections::HashMap;
use std::path::PathBuf;
use structopt::{clap, StructOpt};

/// Copies sets of SSM parameters
#[derive(Debug, StructOpt)]
#[structopt(setting = clap::AppSettings::DeriveDisplayOrder)]
#[derive(Debug, Parser)]
pub(crate) struct PromoteArgs {
/// The architecture of the machine image
#[structopt(long, parse(try_from_str = parse_arch))]
#[arg(long, value_parser = parse_arch)]
arch: ArchitectureValues,

/// The variant name for the current build
#[structopt(long)]
#[arg(long)]
variant: String,

/// Version number (or string) to copy from
#[structopt(long)]
#[arg(long)]
source: String,

/// Version number (or string) to copy to
#[structopt(long)]
#[arg(long)]
target: String,

/// Comma-separated list of regions to promote in, overriding Infra.toml
#[structopt(long, use_delimiter = true)]
#[arg(long, value_delimiter = ',')]
regions: Vec<String>,

/// File holding the parameter templates
#[structopt(long)]
#[arg(long)]
template_path: PathBuf,

/// If set, contains the path to the file holding the original SSM parameters
/// and where the newly promoted parameters will be written
#[structopt(long)]
#[arg(long)]
ssm_parameter_output: Option<PathBuf>,
}

Expand Down
Loading

0 comments on commit 386bba7

Please sign in to comment.