Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ impl App {
fn load_config(cli: &Cli) -> Result<Config> {
let _span = span!(Level::DEBUG, "load_config").entered();

let config = if let Some(config_path) = &cli.config {
// Priority order: 1) subcommand config, 2) global config, 3) auto-discover, 4) default
let config = if let Some(config_path) = cli.get_check_config() {
debug!(
"Loading config from specified path: {}",
"Loading config from subcommand-specified path: {}",
config_path.display()
);
Config::load_from_file(&config_path)?
} else if let Some(config_path) = &cli.config {
debug!(
"Loading config from global config path: {}",
config_path.display()
);
Config::load_from_file(config_path)?
Expand Down
15 changes: 13 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub enum Commands {
/// Paths to check
paths: Vec<PathBuf>,

/// Configuration file path
#[arg(short, long, value_name = "FILE")]
config: Option<PathBuf>,

/// Output format
#[arg(short = 'f', long, default_value = "human")]
format: OutputFormat,
Expand Down Expand Up @@ -186,7 +190,14 @@ impl Cli {
}
}

pub fn parse_shell(shell_str: &str) -> Result<Shell, String> {
pub fn get_check_config(&self) -> Option<PathBuf> {
match &self.command {
Commands::Check { config, .. } => config.clone(),
_ => None,
}
}

pub fn parse_shell(shell_str: &str) -> std::result::Result<Shell, String> {
let shell_lower = shell_str.to_lowercase();
SUPPORTED_SHELLS
.iter()
Expand All @@ -202,7 +213,7 @@ impl Cli {
})
}

pub fn generate_completion(shell_str: &str) -> Result<(), String> {
pub fn generate_completion(shell_str: &str) -> std::result::Result<(), String> {
let shell = Self::parse_shell(shell_str)?;
let mut cmd = Self::command();
generate(shell, &mut cmd, "sizelint", &mut io::stdout());
Expand Down