-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor cli config adjustments into own module
- Loading branch information
1 parent
5990048
commit 859b671
Showing
3 changed files
with
50 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::{ | ||
cli::{ | ||
CategoryOperation, ConfigSubcommands, | ||
ConfigSubcommands::{Category, ChangeType, LegacyVersion, Show, Spelling, TargetRepo}, | ||
HashMapOperation, OptionalOperation, | ||
}, | ||
config, errors, | ||
}; | ||
use std::fs; | ||
|
||
// Handles the CLI subcommands to adjust the configuration file. | ||
pub fn adjust_config(config_subcommand: ConfigSubcommands) -> Result<(), errors::CLIError> { | ||
let mut configuration = config::load()?; | ||
|
||
match config_subcommand { | ||
Category(args) => match args.command { | ||
CategoryOperation::Add { value } => config::add_category(&mut configuration, value)?, | ||
CategoryOperation::Remove { value } => { | ||
config::remove_category(&mut configuration, value)? | ||
} | ||
}, | ||
ChangeType(args) => match args.command { | ||
HashMapOperation::Add { key, value } => { | ||
config::add_into_hashmap(&mut configuration.change_types, key, value)? | ||
} | ||
HashMapOperation::Remove { key } => { | ||
config::remove_from_hashmap(&mut configuration.change_types, key)? | ||
} | ||
}, | ||
Show => println!("{}", configuration), | ||
Spelling(args) => match args.command { | ||
HashMapOperation::Add { key, value } => { | ||
config::add_into_hashmap(&mut configuration.expected_spellings, key, value)? | ||
} | ||
HashMapOperation::Remove { key } => { | ||
config::remove_from_hashmap(&mut configuration.expected_spellings, key)? | ||
} | ||
}, | ||
LegacyVersion(args) => match args.command { | ||
OptionalOperation::Set { value } => configuration.legacy_version = Some(value), | ||
OptionalOperation::Unset => configuration.legacy_version = None, | ||
}, | ||
TargetRepo(args) => config::set_target_repo(&mut configuration, args.value)?, | ||
} | ||
|
||
Ok(fs::write(".clconfig.json", format!("{}", configuration))?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod change_type; | ||
mod changelog; | ||
pub mod cli; | ||
pub mod cli_config; | ||
pub mod config; | ||
mod entry; | ||
pub mod errors; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters