Skip to content

Commit

Permalink
Update clap dependency (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlespinasse authored Jan 7, 2024
1 parent 971dc4d commit 81c8645
Show file tree
Hide file tree
Showing 28 changed files with 280 additions and 249 deletions.
120 changes: 68 additions & 52 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ path = "src/wints/lib.rs"

[dependencies]
anyhow = "1.0"
clap = "2.33.3"
clap = { version = "4.4", features = ["cargo"] }
directories-next = "2.0"
fuzzy-matcher = "0.3"
glob = "0.3"
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ clippy:

clippy-fix:
@echo + $@
cargo clippy --fix --all-features --all-targets --allow-dirty
cargo clippy --fix --all-features --all-targets --allow-dirty --allow-staged

fix:
@echo + $@
cargo fix --allow-dirty
cargo fix --allow-dirty --allow-staged

idioms-fix:
@echo + $@
cargo fix --edition-idioms --allow-dirty
cargo fix --edition-idioms --allow-dirty --allow-staged

update:
@echo + $@
Expand Down
19 changes: 7 additions & 12 deletions src/bin/wints/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::commands;
use anyhow::Result;
use clap::AppSettings;
use wints::util::command_prelude::*;
use clap::Command;

use crate::commands;

pub fn main() -> Result<()> {
let matches = cli().get_matches();
Expand All @@ -17,19 +17,14 @@ pub fn main() -> Result<()> {
command_exec(command_args)
}

fn cli() -> App {
fn cli() -> Command {
let args = commands::global_args();
let subcommands = commands::builtin();

App::new("wints")
Command::new("wints")
.about("What I Need To See - a fuzzy term-based URLs opener")
.version(crate_version!())
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
.args(args.as_ref())
.allow_external_subcommands(true)
.args(args)
.subcommands(subcommands)
}
40 changes: 19 additions & 21 deletions src/bin/wints/commands/add.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
use crate::commands::{general_args, global_arg, module_arg};
use anyhow::Result;
use clap::ArgMatches;
use directories_next::BaseDirs;
use std::path::PathBuf;
use clap::{Arg, ArgMatches, Command};

use wints::ops;
use wints::ops::wints_add::AddOptions;
use wints::util::command_prelude::*;

pub fn command() -> App {
subcommand("add")
use crate::commands::{
general_args, get_global_basedir, get_pathbuf_arg, get_string_arg, global_arg, module_arg,
};

pub fn command() -> Command {
Command::new("add")
.about("Add a url to a context")
.args(general_args().as_ref())
.args(general_args())
.arg(module_arg())
.arg(global_arg())
.arg(
arg("url")
Arg::new("url")
.help("URL to set")
.value_name("URL")
.required(true)
.index(1),
)
.arg(
arg("context")
Arg::new("context")
.help("Context of the URL")
.value_name("CONTEXT")
.required(true)
.index(2),
)
}

pub fn exec(args: &ArgMatches<'_>) -> Result<()> {
let local_basedir = PathBuf::from(args.value_of("config").unwrap().to_string());
let global_basedir = match args.value_of("global-config") {
None => BaseDirs::new().unwrap().home_dir().join(".wints"),
Some(value) => PathBuf::from(value),
};
let module_name = args.value_of("module").unwrap().to_string();
let url = args.value_of("url").unwrap().to_string();
let context = args.value_of("context").unwrap().to_string();
let global_module = args.is_present("global");
let dry_run = args.is_present("dry-run");
pub fn exec(args: &ArgMatches) -> Result<()> {
let local_basedir = get_pathbuf_arg(args, "config");
let global_basedir = get_global_basedir(args);
let module_name = get_string_arg(args, "module");
let url = get_string_arg(args, "url");
let context = get_string_arg(args, "context");
let global_module = args.get_flag("global");
let dry_run = args.get_flag("dry-run");

ops::wints_add::add(AddOptions {
local_basedir,
Expand Down
39 changes: 19 additions & 20 deletions src/bin/wints/commands/init.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
use crate::commands::{general_args, global_arg, module_arg};
use anyhow::Result;
use clap::ArgMatches;
use directories_next::BaseDirs;
use std::path::PathBuf;
use clap::builder::PossibleValuesParser;
use clap::{Arg, ArgMatches, Command};

use wints::ops;
use wints::ops::wints_init::InitOptions;
use wints::util::command_prelude::*;

pub fn command() -> App {
subcommand("init")
use crate::commands::{
general_args, get_global_basedir, get_pathbuf_arg, get_string_arg, global_arg, module_arg,
};

pub fn command() -> Command {
Command::new("init")
.about("Initialise a new module")
.args(general_args().as_ref())
.args(general_args())
.arg(module_arg())
.arg(global_arg())
.arg(
arg("template")
Arg::new("template")
.help("Template name to use")
.value_name("TEMPLATE")
.possible_values(&["empty", "default"])
.value_parser(PossibleValuesParser::new(["empty", "default"]))
.default_value("empty")
.index(1),
)
}

pub fn exec(args: &ArgMatches<'_>) -> Result<()> {
let local_basedir = PathBuf::from(args.value_of("config").unwrap().to_string());
let global_basedir = match args.value_of("global-config") {
None => BaseDirs::new().unwrap().home_dir().join(".wints"),
Some(value) => PathBuf::from(value),
};
let module_name = args.value_of("module").unwrap().to_string();
let template = args.value_of("template").unwrap().to_string();
let global_module = args.is_present("global");
let dry_run = args.is_present("dry-run");
pub fn exec(args: &ArgMatches) -> Result<()> {
let local_basedir = get_pathbuf_arg(args, "config");
let global_basedir = get_global_basedir(args);
let module_name = get_string_arg(args, "module");
let template = get_string_arg(args, "template");
let global_module = args.get_flag("global");
let dry_run = args.get_flag("dry-run");

ops::wints_init::init(InitOptions {
local_basedir,
Expand Down
Loading

0 comments on commit 81c8645

Please sign in to comment.