Skip to content

Commit

Permalink
b: Replace structopt with clap
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 10, 2023
1 parent f953c24 commit d97ba93
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 105 deletions.
149 changes: 64 additions & 85 deletions b/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 b/crates/application/Cargo.toml
Expand Up @@ -9,12 +9,13 @@ edition = "2018"
[dependencies]
adapter_fs = { path = "../adapter_fs" }
anyhow = "1.0.41"
clap = { version = "4.1.8", features = ["derive"] }
clap_complete = "4.1.4"
entity = { path = "../entity" }
limited-date-time = { git = "https://github.com/bouzuya/rust-limited-date-time", tag = "0.15.0" }
nom = "6.1.2"
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
structopt = "0.3.21"
thiserror = "1.0.24"
use_case = { path = "../use_case" }
xdg = "2.4.0"
Expand Down
37 changes: 18 additions & 19 deletions b/crates/application/src/main.rs
Expand Up @@ -2,46 +2,44 @@ mod command;
mod config;

use adapter_fs::FsBRepository;
use clap_complete::{generate, Shell};
use config::{Config, ConfigRepository};
use entity::BId;
use limited_date_time::TimeZoneOffset;
use std::{io, path::PathBuf, str::FromStr};
use structopt::{clap::Shell, StructOpt};
use use_case::{HasBRepository, HasListUseCase, HasViewUseCase};

#[derive(Debug, StructOpt)]
#[derive(Debug, clap::Parser)]
struct Opt {
#[structopt(subcommand)]
#[command(subcommand)]
subcommand: Subcommand,
}

#[derive(Debug, StructOpt)]
#[derive(Debug, clap::Subcommand)]
enum Subcommand {
#[structopt(name = "completion", about = "Prints the shell's completion script")]
/// Prints the shell's completion script
Completion {
#[structopt(name = "SHELL", help = "the shell", possible_values = &Shell::variants())]
#[arg(name = "SHELL", help = "the shell", value_enum)]
shell: Shell,
},
#[structopt(name = "list", about = "Lists b files")]
/// Lists b files
List {
#[structopt(long = "json")]
#[arg(long)]
json: bool,
query: String,
},
#[structopt(name = "new", about = "Creates a new file")]
/// Creates a new file
New {
#[structopt(short = "d", long = "data-file", help = "The data file")]
/// The data file
#[arg(short, long)]
data_file: PathBuf,
#[structopt(
short = "t",
long = "template",
help = "The template file or directory"
)]
/// The template file or directory
#[arg(short, long)]
template: PathBuf,
},
#[structopt(name = "view", about = "Views the b file")]
/// Views the b file
View {
#[structopt(name = "BID")]
#[arg(name = "BID")]
id: BId,
},
}
Expand Down Expand Up @@ -84,10 +82,11 @@ fn build_app(config: Config) -> anyhow::Result<App> {
}

fn main() -> anyhow::Result<()> {
let opt = Opt::from_args();
let opt = <Opt as clap::Parser>::parse();
match opt.subcommand {
Subcommand::Completion { shell } => {
Opt::clap().gen_completions_to("b", shell, &mut io::stdout());
let mut command = <Opt as clap::CommandFactory>::command();
generate(shell, &mut command, "b", &mut io::stdout());
Ok(())
}
Subcommand::List { json, query } => {
Expand Down

0 comments on commit d97ba93

Please sign in to comment.