Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to clap #29

Merged
merged 2 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 44 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ license = "MIT"
edition = "2021"
repository = "https://github.com/LPGhatguy/aftman"
readme = "README.md"
authors = ["Lucien Greathouse <me@lpghatguy.com>"]

[workspace]
members = ["test-util"]

[dependencies]
anyhow = "1.0.43"
atty = "0.2.14"
clap = { version = "3.2.17", features = ["derive"] }
dialoguer = "0.9.0"
dirs = "3.0.2"
env_logger = "0.9.0"
Expand All @@ -24,7 +26,6 @@ reqwest = { version = "0.11.4", features = ["blocking"] }
semver = { version = "1.0.4", features = ["serde"] }
serde = { version = "1.0.129", features = ["derive"] }
serde_json = "1.0.67"
structopt = "0.3.22"
tempfile = "3.3.0"
toml = "0.5.8"
toml_edit = "0.14.4"
Expand Down
33 changes: 17 additions & 16 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::env::current_dir;
use std::path::PathBuf;

use anyhow::{bail, Context};
use structopt::StructOpt;
use clap::Parser;

use crate::home::Home;
use crate::manifest::Manifest;
Expand All @@ -13,9 +13,10 @@ use crate::tool_spec::ToolSpec;
use crate::tool_storage::{InstalledToolsCache, ToolStorage};
use crate::trust::{TrustCache, TrustMode};

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
#[clap(author, version, about)]
pub struct Args {
#[structopt(subcommand)]
#[clap(subcommand)]
pub subcommand: Subcommand,
}

Expand All @@ -35,7 +36,7 @@ impl Args {
}
}

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub enum Subcommand {
Init(InitSubcommand),
List(ListSubcommand),
Expand All @@ -48,7 +49,7 @@ pub enum Subcommand {
}

/// Initialize a new Aftman manifest file.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct InitSubcommand {
/// The folder to initialize the manifest file in. Defaults to the current
/// directory.
Expand All @@ -69,7 +70,7 @@ impl InitSubcommand {
}

/// Lists all existing tools managed by Aftman.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct ListSubcommand {}

impl ListSubcommand {
Expand Down Expand Up @@ -106,7 +107,7 @@ impl ListSubcommand {
}

/// Adds a new tool to Aftman and installs it.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct AddSubcommand {
/// A tool spec describing where to get the tool and what version to
/// install.
Expand All @@ -117,7 +118,7 @@ pub struct AddSubcommand {

/// Install this tool globally by adding it to ~/.aftman/aftman.toml instead
/// of installing it to the nearest aftman.toml file.
#[structopt(long)]
#[clap(long)]
pub global: bool,
}

Expand All @@ -132,27 +133,27 @@ impl AddSubcommand {
/// Tools can be specified either by their alias or by their name.
///
/// If no tools are listed, Aftman will update all installed tools.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct UpdateSubcommand {
/// One or more tools to update. If no tools are given, update all tools.
pub aliases_or_specs: Vec<String>,

/// Update this tool globally by adding it to ~/.aftman/aftman.toml instead
/// of installing it to the nearest aftman.toml file that mentions it.
#[structopt(long)]
#[clap(long)]
pub global: bool,

/// Ignore semantic versioning and upgrade to the latest stable versions.
#[structopt(long)]
#[clap(long)]
pub latest: bool,
}

/// Install all tools listed by Aftman files from the current directory.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct InstallSubcommand {
/// Skip checking if these tools have been installed before. It is
/// recommended to only run this on CI machines.
#[structopt(long)]
#[clap(long)]
pub no_trust_check: bool,
}

Expand All @@ -169,7 +170,7 @@ impl InstallSubcommand {
}

/// Mark the given tool name as being trusted.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct TrustSubcommand {
/// The tool to mark as trusted.
pub name: ToolName,
Expand All @@ -188,12 +189,12 @@ impl TrustSubcommand {
}

/// Update Aftman from the internet.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct SelfUpdateSubcommand {}

/// Install Aftman and update all references to it. Run this command if you've
/// just upgraded Aftman manually.
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub struct SelfInstallSubcommand {}

impl SelfInstallSubcommand {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod trust;
use std::env::{consts::EXE_SUFFIX, current_dir, current_exe};

use anyhow::{bail, format_err, Context};
use structopt::StructOpt;
use clap::Parser;

use crate::cli::Args;
use crate::home::Home;
Expand Down