summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-04-25 19:25:41 +0300
committerLars Wirzenius <liw@liw.fi>2022-04-25 19:25:41 +0300
commit398f412253d9a9c00ba7fc4dfc48591a8c17789b (patch)
tree3dd6e59954434782941c5cca4d0562e4041777b6 /src
parent4305a22cd719ec1aaadb46796bbd7fc84f2161f0 (diff)
downloadjt2-398f412253d9a9c00ba7fc4dfc48591a8c17789b.tar.gz
chore: port from structopt to clap v3
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/bin/jt.rs4
-rw-r--r--src/cmd.rs32
-rw-r--r--src/opt.rs14
3 files changed, 25 insertions, 25 deletions
diff --git a/src/bin/jt.rs b/src/bin/jt.rs
index 11fc45d..21bf254 100644
--- a/src/bin/jt.rs
+++ b/src/bin/jt.rs
@@ -1,7 +1,7 @@
use jt::config::Configuration;
use jt::opt::{Opt, SubCommand};
-use structopt::StructOpt;
+use clap::Parser;
fn main() {
if let Err(err) = do_work() {
@@ -12,7 +12,7 @@ fn main() {
fn do_work() -> anyhow::Result<()> {
pretty_env_logger::init_custom_env("JT_LOG");
- let opt = Opt::from_args();
+ let opt = Opt::parse();
let config = Configuration::read(&opt)?;
match opt.cmd {
SubCommand::Config(x) => x.run(&config)?,
diff --git a/src/cmd.rs b/src/cmd.rs
index 9cec3b5..07f985f 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -1,11 +1,11 @@
use crate::config::Configuration;
use crate::error::JournalError;
use crate::journal::Journal;
+use clap::Parser;
use log::debug;
use std::path::PathBuf;
-use structopt::StructOpt;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Config {}
impl Config {
@@ -15,12 +15,12 @@ impl Config {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Init {
- #[structopt(help = "Short name for journal")]
+ #[clap(help = "Short name for journal")]
journalname: String,
- #[structopt(help = "Short description of journal, its title")]
+ #[clap(help = "Short description of journal, its title")]
description: String,
}
@@ -35,7 +35,7 @@ impl Init {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct IsJournal {}
impl IsJournal {
@@ -49,12 +49,12 @@ impl IsJournal {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct New {
- #[structopt(help = "Title of new draft")]
+ #[clap(help = "Title of new draft")]
title: String,
- #[structopt(long, help = "Add link to a topic page")]
+ #[clap(long, help = "Add link to a topic page")]
topic: Option<PathBuf>,
}
@@ -66,7 +66,7 @@ impl New {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct List {}
impl List {
@@ -77,12 +77,12 @@ impl List {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct NewTopic {
- #[structopt(help = "Path to topic page in journal")]
+ #[clap(help = "Path to topic page in journal")]
path: PathBuf,
- #[structopt(help = "Title of topic page")]
+ #[clap(help = "Title of topic page")]
title: String,
}
@@ -94,7 +94,7 @@ impl NewTopic {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Edit {
/// Draft id.
draft: String,
@@ -109,7 +109,7 @@ impl Edit {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Remove {
/// Draft id.
draft: String,
@@ -124,7 +124,7 @@ impl Remove {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Finish {
/// Draft id.
draft: String,
diff --git a/src/opt.rs b/src/opt.rs
index 9170e0f..5a81ab6 100644
--- a/src/opt.rs
+++ b/src/opt.rs
@@ -1,26 +1,26 @@
//! Command line options.
use crate::cmd;
+use clap::Parser;
use std::path::PathBuf;
-use structopt::StructOpt;
/// A parsed command line.
-#[derive(Debug, StructOpt)]
-#[structopt(about = "maintain a journal")]
+#[derive(Debug, Parser)]
+#[clap(about = "maintain a journal")]
pub struct Opt {
/// Global options, common for all subcommands.
- #[structopt(flatten)]
+ #[clap(flatten)]
pub global: GlobalOptions,
/// The subcommand.
- #[structopt(subcommand)]
+ #[clap(subcommand)]
pub cmd: SubCommand,
}
/// Global options.
///
/// These options are common to all subcommands.
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct GlobalOptions {
/// Which configuration file to read.
#[structopt(short, long, help = "Configuration file")]
@@ -44,7 +44,7 @@ pub struct GlobalOptions {
}
/// A subcommand.
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub enum SubCommand {
/// Show configuration.
Config(cmd::Config),