summaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2022-06-07 18:59:31 +0200
committerCanop <cano.petrole@gmail.com>2022-06-07 18:59:31 +0200
commit1c61e362e614afebfd55591fbc37efde084795ad (patch)
treea449aa4864427dd38efad01b2d66bdb8e8a1ae75 /src/cli
parent4bcc94ba280eb342e585d9070ddc5adccfa39950 (diff)
update from clap2 to clap3
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/clap_args.rs124
-rw-r--r--src/cli/install_launch_args.rs2
-rw-r--r--src/cli/mod.rs2
3 files changed, 66 insertions, 62 deletions
diff --git a/src/cli/clap_args.rs b/src/cli/clap_args.rs
index bf4fe69..0ac9524 100644
--- a/src/cli/clap_args.rs
+++ b/src/cli/clap_args.rs
@@ -1,166 +1,165 @@
/// this module generate the clap App, which defines
/// launch arguments
-/// declare the possible CLI arguments
-pub fn clap_app() -> clap::App<'static, 'static> {
- let app = clap::App::new("broot")
+/// Declare the possible CLI arguments
+pub fn clap_app() -> clap::Command<'static> {
+ let app = clap::Command::new("broot")
.version(env!("CARGO_PKG_VERSION"))
.author("dystroy <denys.seguret@gmail.com>")
.about(
"A tree explorer and a customizable launcher\n\
Complete documentation lives at https://dystroy.org/broot"
)
- .setting(clap::AppSettings::ColoredHelp)
- .arg(clap::Arg::with_name("ROOT").help("sets the root directory"))
+ .arg(clap::Arg::new("ROOT").help("sets the root directory"))
// tree flags
.arg(
- clap::Arg::with_name("dates")
- .short("d")
+ clap::Arg::new("dates")
+ .short('d')
.long("dates")
.help("Show the last modified date of files and directories"),
)
.arg(
- clap::Arg::with_name("no-dates")
- .short("D")
+ clap::Arg::new("no-dates")
+ .short('D')
.long("no-dates")
.help("Don't show last modified date"),
)
.arg(
- clap::Arg::with_name("only-folders")
- .short("f")
+ clap::Arg::new("only-folders")
+ .short('f')
.long("only-folders")
.help("Only show folders"),
)
.arg(
- clap::Arg::with_name("no-only-folders")
- .short("F")
+ clap::Arg::new("no-only-folders")
+ .short('F')
.long("no-only-folders")
.help("Show folders and files alike"),
)
.arg(
- clap::Arg::with_name("show-root-fs")
+ clap::Arg::new("show-root-fs")
.long("show-root-fs")
.help("Show filesystem info on top"),
)
.arg(
- clap::Arg::with_name("show-git-info")
- .short("g")
+ clap::Arg::new("show-git-info")
+ .short('g')
.long("show-git-info")
.help("Show git statuses on files and stats on repo"),
)
.arg(
- clap::Arg::with_name("no-show-git-info")
- .short("G")
+ clap::Arg::new("no-show-git-info")
+ .short('G')
.long("no-show-git-info")
.help("Don't show git statuses on files"),
)
.arg(
- clap::Arg::with_name("git-status")
+ clap::Arg::new("git-status")
.long("git-status")
.help("Only show files having an interesting git status, including hidden ones"),
)
.arg(
- clap::Arg::with_name("hidden")
- .short("h")
+ clap::Arg::new("hidden")
+ .short('h')
.long("hidden")
.help("Show hidden files"),
)
.arg(
- clap::Arg::with_name("no-hidden")
- .short("H")
+ clap::Arg::new("no-hidden")
+ .short('H')
.long("no-hidden")
.help("Don't show hidden files"),
)
.arg(
- clap::Arg::with_name("show-gitignored")
- .short("i")
+ clap::Arg::new("show-gitignored")
+ .short('i')
.long("show-gitignored")
.help("Show files which should be ignored according to git"),
)
.arg(
- clap::Arg::with_name("no-show-gitignored")
- .short("I")
+ clap::Arg::new("no-show-gitignored")
+ .short('I')
.long("no-show-gitignored")
.help("Don't show gitignored files"),
)
.arg(
- clap::Arg::with_name("permissions")
- .short("p")
+ clap::Arg::new("permissions")
+ .short('p')
.long("permissions")
.help("Show permissions, with owner and group"),
)
.arg(
- clap::Arg::with_name("no-permissions")
- .short("P")
+ clap::Arg::new("no-permissions")
+ .short('P')
.long("no-permissions")
.help("Don't show permissions"),
)
.arg(
- clap::Arg::with_name("sizes")
- .short("s")
+ clap::Arg::new("sizes")
+ .short('s')
.long("sizes")
.help("Show the size of files and directories"),
)
.arg(
- clap::Arg::with_name("no-sizes")
- .short("S")
+ clap::Arg::new("no-sizes")
+ .short('S')
.long("no-sizes")
.help("Don't show sizes"),
)
.arg(
- clap::Arg::with_name("sort-by-count")
+ clap::Arg::new("sort-by-count")
.long("sort-by-count")
.help("Sort by count (only show one level of the tree)"),
)
.arg(
- clap::Arg::with_name("sort-by-date")
+ clap::Arg::new("sort-by-date")
.long("sort-by-date")
.help("Sort by date (only show one level of the tree)"),
)
.arg(
- clap::Arg::with_name("sort-by-size")
+ clap::Arg::new("sort-by-size")
.long("sort-by-size")
.help("Sort by size (only show one level of the tree)"),
)
.arg(
- clap::Arg::with_name("whale-spotting")
- .short("w")
+ clap::Arg::new("whale-spotting")
+ .short('w')
.long("whale-spotting")
.help("Sort by size, show ignored and hidden files"),
)
.arg(
- clap::Arg::with_name("no-sort")
+ clap::Arg::new("no-sort")
.long("no-sort")
.help("Don't sort"),
)
.arg(
- clap::Arg::with_name("trim-root")
- .short("t")
+ clap::Arg::new("trim-root")
+ .short('t')
.long("trim-root")
.help("Trim the root too and don't show a scrollbar"),
)
.arg(
- clap::Arg::with_name("no-trim-root")
- .short("T")
+ clap::Arg::new("no-trim-root")
+ .short('T')
.long("no-trim-root")
.help("Don't trim the root level, show a scrollbar"),
)
// other options
.arg(
- clap::Arg::with_name("cmd-export-path")
+ clap::Arg::new("cmd-export-path")
.long("outcmd")
.takes_value(true)
.help("Where to write the produced cmd (if any)"),
)
.arg(
- clap::Arg::with_name("commands")
- .short("c")
+ clap::Arg::new("commands")
+ .short('c')
.long("cmd")
.takes_value(true)
.help("Semicolon separated commands to execute"),
)
.arg(
- clap::Arg::with_name("color")
+ clap::Arg::new("color")
.long("color")
.takes_value(true)
.possible_values(&["yes", "no", "auto"])
@@ -168,32 +167,32 @@ pub fn clap_app() -> clap::App<'static, 'static> {
.help("Whether to have styles and colors (auto is default and usually OK)"),
)
.arg(
- clap::Arg::with_name("conf")
+ clap::Arg::new("conf")
.long("conf")
.takes_value(true)
.help("Semicolon separated paths to specific config files"),
)
.arg(
- clap::Arg::with_name("height")
+ clap::Arg::new("height")
.long("height")
.help("Height (if you don't want to fill the screen or for file export)")
.takes_value(true),
)
.arg(
- clap::Arg::with_name("file-export-path") // deprecated since broot 1.6
- .short("o")
+ clap::Arg::new("file-export-path") // deprecated since broot 1.6
+ .short('o')
.long("out")
.takes_value(true)
- .hidden(true)
+ .hide(true)
.help("Where to write the produced path (if any)"),
)
.arg(
- clap::Arg::with_name("install")
+ clap::Arg::new("install")
.long("install")
.help("Install or reinstall the br shell function"),
)
.arg(
- clap::Arg::with_name("set-install-state")
+ clap::Arg::new("set-install-state")
.long("set-install-state")
.takes_value(true)
.value_name("state")
@@ -201,7 +200,7 @@ pub fn clap_app() -> clap::App<'static, 'static> {
.help("Set the installation state (for use in install script)"),
)
.arg(
- clap::Arg::with_name("print-shell-function")
+ clap::Arg::new("print-shell-function")
.long("print-shell-function")
.takes_value(true)
.value_name("shell")
@@ -211,21 +210,26 @@ pub fn clap_app() -> clap::App<'static, 'static> {
#[cfg(unix)]
let app = app
.arg(
- clap::Arg::with_name("listen")
+ clap::Arg::new("listen")
.long("listen")
.takes_value(true)
.help("Listen for commands")
)
.arg(
- clap::Arg::with_name("get-root")
+ clap::Arg::new("get-root")
.long("get-root")
.help("Ask for the current root of the remote broot")
)
.arg(
- clap::Arg::with_name("send")
+ clap::Arg::new("send")
.long("send")
.takes_value(true)
.help("send commands to a remote broot then quits")
);
app
}
+
+#[test]
+fn verify_app() {
+ clap_app().debug_assert();
+}
diff --git a/src/cli/install_launch_args.rs b/src/cli/install_launch_args.rs
index 5b8ef39..c688e12 100644
--- a/src/cli/install_launch_args.rs
+++ b/src/cli/install_launch_args.rs
@@ -21,7 +21,7 @@ pub struct InstallLaunchArgs {
pub print_shell_function: Option<String>, // shell function to print on stdout
}
impl InstallLaunchArgs {
- pub fn from(cli_args: &ArgMatches<'_>) -> Result<Self, ProgramError> {
+ pub fn from(cli_args: &ArgMatches) -> Result<Self, ProgramError> {
let mut install = None;
if let Ok(s) = env::var("BR_INSTALL") {
if s == "yes" {
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 3bc64c5..29c5152 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -50,7 +50,7 @@ fn canonicalize_root(root: &Path) -> io::Result<PathBuf> {
})
}
-fn get_root_path(cli_args: &ArgMatches<'_>) -> Result<PathBuf, ProgramError> {
+fn get_root_path(cli_args: &ArgMatches) -> Result<PathBuf, ProgramError> {
let mut root = cli_args
.value_of("ROOT")
.map_or(env::current_dir()?, PathBuf::from);