Update clap dependency

This commit is contained in:
timvisee
2023-01-11 12:43:38 +01:00
parent 026aa58b5d
commit 0e4d18e9f6
7 changed files with 165 additions and 57 deletions

View File

@@ -9,7 +9,7 @@ use crate::util::error::{quit, quit_error, ErrorHintsBuilder};
/// Invoke config test command.
pub fn invoke(matches: &ArgMatches) {
// Get config path, attempt to canonicalize
let mut path = PathBuf::from(matches.value_of("config").unwrap());
let mut path = PathBuf::from(matches.get_one::<String>("config").unwrap());
if let Ok(p) = path.canonicalize() {
path = p;
}

View File

@@ -8,7 +8,7 @@ use crate::util::error::{quit_error, quit_error_msg, ErrorHintsBuilder};
/// Invoke config test command.
pub fn invoke(matches: &ArgMatches) {
// Get config path, attempt to canonicalize
let mut path = PathBuf::from(matches.value_of("config").unwrap());
let mut path = PathBuf::from(matches.get_one::<String>("config").unwrap());
if let Ok(p) = path.canonicalize() {
path = p;
}

View File

@@ -1,23 +1,28 @@
use clap::{App, AppSettings, Arg};
use clap::{Arg, Command};
/// The clap app for CLI argument parsing.
pub fn app() -> App<'static> {
App::new(crate_name!())
pub fn app() -> Command {
Command::new(crate_name!())
.version(crate_version!())
.author(crate_authors!())
.about(crate_description!())
.subcommand(
App::new("start")
Command::new("start")
.alias("run")
.about("Start lazymc and server (default)"),
)
.subcommand(
App::new("config")
Command::new("config")
.alias("cfg")
.about("Config actions")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(App::new("generate").alias("gen").about("Generate config"))
.subcommand(App::new("test").about("Test config")),
.arg_required_else_help(true)
.subcommand_required(true)
.subcommand(
Command::new("generate")
.alias("gen")
.about("Generate config"),
)
.subcommand(Command::new("test").about("Test config")),
)
.arg(
Arg::new("config")
@@ -28,6 +33,6 @@ pub fn app() -> App<'static> {
.value_name("FILE")
.default_value(crate::config::CONFIG_FILE)
.help("Use config file")
.takes_value(true),
.num_args(1),
)
}

View File

@@ -22,7 +22,7 @@ const CONFIG_VERSION: &str = "0.2.6";
/// Quits with an error message on failure.
pub fn load(matches: &ArgMatches) -> Config {
// Get config path, attempt to canonicalize
let mut path = PathBuf::from(matches.value_of("config").unwrap());
let mut path = PathBuf::from(matches.get_one::<String>("config").unwrap());
if let Ok(p) = path.canonicalize() {
path = p;
}

View File

@@ -29,7 +29,7 @@ pub(crate) mod util;
use std::env;
use clap::App;
use clap::Command;
// Compile time feature compatability check.
#[cfg(all(windows, not(feature = "rcon")))]
@@ -63,7 +63,7 @@ fn init_log() {
}
/// Invoke an action.
fn invoke_action(app: App) -> Result<(), ()> {
fn invoke_action(app: Command) -> Result<(), ()> {
let matches = app.get_matches();
// Config operations