add 'ta config path'

This commit is contained in:
Dustin J. Mitchell 2021-05-21 22:39:10 -04:00
parent 7f046a8e27
commit 45db886f2a
2 changed files with 24 additions and 9 deletions

View file

@ -1,13 +1,15 @@
use super::args::{any, arg_matching, literal}; use super::args::{any, arg_matching, literal};
use super::ArgList; use super::ArgList;
use crate::usage; use crate::usage;
use nom::{combinator::*, sequence::*, IResult}; use nom::{branch::alt, combinator::*, sequence::*, IResult};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
/// A config operation /// A config operation
pub(crate) enum ConfigOperation { pub(crate) enum ConfigOperation {
/// Set a configuration value /// Set a configuration value
Set(String, String), Set(String, String),
/// Show configuration path
Path,
} }
impl ConfigOperation { impl ConfigOperation {
@ -15,14 +17,20 @@ impl ConfigOperation {
fn set_to_op(input: (&str, &str, &str)) -> Result<ConfigOperation, ()> { fn set_to_op(input: (&str, &str, &str)) -> Result<ConfigOperation, ()> {
Ok(ConfigOperation::Set(input.1.to_owned(), input.2.to_owned())) Ok(ConfigOperation::Set(input.1.to_owned(), input.2.to_owned()))
} }
map_res( fn path_to_op(_: &str) -> Result<ConfigOperation, ()> {
tuple(( Ok(ConfigOperation::Path)
arg_matching(literal("set")), }
arg_matching(any), alt((
arg_matching(any), map_res(
)), tuple((
set_to_op, arg_matching(literal("set")),
)(input) 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) { pub(super) fn get_usage(u: &mut usage::Usage) {

View file

@ -19,6 +19,13 @@ pub(crate) fn execute<W: WriteColor>(
writeln!(w, "{:?}.", filename)?; writeln!(w, "{:?}.", filename)?;
w.set_color(ColorSpec::new().set_bold(false))?; 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(()) Ok(())
} }