mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
add 'ta config path'
This commit is contained in:
parent
7f046a8e27
commit
45db886f2a
2 changed files with 24 additions and 9 deletions
|
@ -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<ConfigOperation, ()> {
|
||||
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<ConfigOperation, ()> {
|
||||
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) {
|
||||
|
|
|
@ -19,6 +19,13 @@ pub(crate) fn execute<W: WriteColor>(
|
|||
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(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue