From 45db886f2a1f86460f4088597242058fb2e9125b Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Fri, 21 May 2021 22:39:10 -0400 Subject: [PATCH] add 'ta config path' --- cli/src/argparse/config.rs | 26 +++++++++++++++++--------- cli/src/invocation/cmd/config.rs | 7 +++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cli/src/argparse/config.rs b/cli/src/argparse/config.rs index 924164564..209000a4e 100644 --- a/cli/src/argparse/config.rs +++ b/cli/src/argparse/config.rs @@ -1,13 +1,15 @@ use super::args::{any, arg_matching, literal}; use super::ArgList; use crate::usage; -use nom::{combinator::*, sequence::*, IResult}; +use nom::{branch::alt, combinator::*, sequence::*, IResult}; #[derive(Debug, PartialEq)] /// A config operation pub(crate) enum ConfigOperation { /// Set a configuration value Set(String, String), + /// Show configuration path + Path, } impl ConfigOperation { @@ -15,14 +17,20 @@ impl ConfigOperation { fn set_to_op(input: (&str, &str, &str)) -> Result { Ok(ConfigOperation::Set(input.1.to_owned(), input.2.to_owned())) } - map_res( - tuple(( - arg_matching(literal("set")), - arg_matching(any), - arg_matching(any), - )), - set_to_op, - )(input) + fn path_to_op(_: &str) -> Result { + Ok(ConfigOperation::Path) + } + alt(( + map_res( + tuple(( + arg_matching(literal("set")), + arg_matching(any), + arg_matching(any), + )), + set_to_op, + ), + map_res(arg_matching(literal("path")), path_to_op), + ))(input) } pub(super) fn get_usage(u: &mut usage::Usage) { diff --git a/cli/src/invocation/cmd/config.rs b/cli/src/invocation/cmd/config.rs index 2b57aa52d..fc8aa6a3f 100644 --- a/cli/src/invocation/cmd/config.rs +++ b/cli/src/invocation/cmd/config.rs @@ -19,6 +19,13 @@ pub(crate) fn execute( writeln!(w, "{:?}.", filename)?; w.set_color(ColorSpec::new().set_bold(false))?; } + ConfigOperation::Path => { + if let Some(ref filename) = settings.filename { + writeln!(w, "{}", filename.to_string_lossy())?; + } else { + return Err(anyhow::anyhow!("No configuration filename found").into()); + } + } } Ok(()) }