diff --git a/src/alias_style.rs b/src/alias_style.rs new file mode 100644 index 0000000000..ade5b2fe88 --- /dev/null +++ b/src/alias_style.rs @@ -0,0 +1,8 @@ +use super::*; + +#[derive(Debug, PartialEq, Clone, ValueEnum)] +pub(crate) enum AliasStyle { + Inline, + InlineLeft, + Recipe, +} diff --git a/src/config.rs b/src/config.rs index d5b9850326..ca4c58e87c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,7 @@ use { #[derive(Debug, PartialEq)] pub(crate) struct Config { + pub(crate) alias_style: AliasStyle, pub(crate) check: bool, pub(crate) color: Color, pub(crate) command_color: Option, @@ -18,14 +19,12 @@ pub(crate) struct Config { pub(crate) dump_format: DumpFormat, pub(crate) explain: bool, pub(crate) highlight: bool, - pub(crate) inline_aliases_left: bool, pub(crate) invocation_directory: PathBuf, pub(crate) list_heading: String, pub(crate) list_prefix: String, pub(crate) list_submodules: bool, pub(crate) load_dotenv: bool, pub(crate) no_aliases: bool, - pub(crate) no_inline_aliases: bool, pub(crate) no_dependencies: bool, pub(crate) one: bool, pub(crate) search_config: SearchConfig, @@ -82,6 +81,7 @@ mod cmd { } mod arg { + pub(crate) const ALIAS_STYLE: &str = "ALIAS_STYLE"; pub(crate) const ARGUMENTS: &str = "ARGUMENTS"; pub(crate) const CHECK: &str = "CHECK"; pub(crate) const CHOOSER: &str = "CHOOSER"; @@ -95,7 +95,6 @@ mod arg { pub(crate) const EXPLAIN: &str = "EXPLAIN"; pub(crate) const GLOBAL_JUSTFILE: &str = "GLOBAL-JUSTFILE"; pub(crate) const HIGHLIGHT: &str = "HIGHLIGHT"; - pub(crate) const INLINE_ALIASES_LEFT: &str = "INLINE-ALIASES-LEFT"; pub(crate) const JUSTFILE: &str = "JUSTFILE"; pub(crate) const LIST_HEADING: &str = "LIST-HEADING"; pub(crate) const LIST_PREFIX: &str = "LIST-PREFIX"; @@ -104,7 +103,6 @@ mod arg { pub(crate) const NO_DEPS: &str = "NO-DEPS"; pub(crate) const NO_DOTENV: &str = "NO-DOTENV"; pub(crate) const NO_HIGHLIGHT: &str = "NO-HIGHLIGHT"; - pub(crate) const NO_INLINE_ALIASES: &str = "NO-INLINE-ALIASES"; pub(crate) const ONE: &str = "ONE"; pub(crate) const QUIET: &str = "QUIET"; pub(crate) const SET: &str = "SET"; @@ -139,6 +137,16 @@ impl Config { .placeholder(AnsiColor::Green.on_default()) .usage(AnsiColor::Yellow.on_default()), ) + .arg( + Arg::new(arg::ALIAS_STYLE) + .long("alias-style") + .env("JUST_ALIAS_STYLE") + .action(ArgAction::Set) + .value_parser(clap::value_parser!(AliasStyle)) + .default_value("inline") + .help("Set the style that the list command will display aliases") + .conflicts_with(arg::NO_ALIASES), + ) .arg( Arg::new(arg::CHECK) .long("check") @@ -238,15 +246,6 @@ impl Config { .help("Highlight echoed recipe lines in bold") .overrides_with(arg::NO_HIGHLIGHT), ) - .arg( - Arg::new(arg::INLINE_ALIASES_LEFT) - .long("inline-aliases-left") - .env("JUST_INLINE_ALIASES_LEFT") - .action(ArgAction::SetTrue) - .help("Display inlined recipe aliases to the left of their doc in listing") - .conflicts_with(arg::NO_ALIASES) - .conflicts_with(arg::NO_INLINE_ALIASES), - ) .arg( Arg::new(arg::JUSTFILE) .short('f') @@ -289,14 +288,6 @@ impl Config { .action(ArgAction::SetTrue) .help("Don't show aliases in list"), ) - .arg( - Arg::new(arg::NO_INLINE_ALIASES) - .long("no-inline-aliases") - .env("JUST_NO_INLINE_ALIASES") - .action(ArgAction::SetTrue) - .help("Don't show aliases inline with recipe docs in list") - .conflicts_with(arg::NO_ALIASES), - ) .arg( Arg::new(arg::NO_DEPS) .long("no-deps") @@ -727,6 +718,10 @@ impl Config { let explain = matches.get_flag(arg::EXPLAIN); Ok(Self { + alias_style: matches + .get_one::(arg::ALIAS_STYLE) + .unwrap() + .clone(), check: matches.get_flag(arg::CHECK), color: (*matches.get_one::(arg::COLOR).unwrap()).into(), command_color: matches @@ -744,14 +739,12 @@ impl Config { .clone(), explain, highlight: !matches.get_flag(arg::NO_HIGHLIGHT), - inline_aliases_left: matches.get_flag(arg::INLINE_ALIASES_LEFT), invocation_directory: env::current_dir().context(config_error::CurrentDirContext)?, list_heading: matches.get_one::(arg::LIST_HEADING).unwrap().into(), list_prefix: matches.get_one::(arg::LIST_PREFIX).unwrap().into(), list_submodules: matches.get_flag(arg::LIST_SUBMODULES), load_dotenv: !matches.get_flag(arg::NO_DOTENV), no_aliases: matches.get_flag(arg::NO_ALIASES), - no_inline_aliases: matches.get_flag(arg::NO_INLINE_ALIASES), no_dependencies: matches.get_flag(arg::NO_DEPS), one: matches.get_flag(arg::ONE), search_config, diff --git a/src/lib.rs b/src/lib.rs index 75e3332be4..ad0ce0d0b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,16 +6,16 @@ pub(crate) use { crate::{ - alias::Alias, analyzer::Analyzer, argument_parser::ArgumentParser, assignment::Assignment, - assignment_resolver::AssignmentResolver, ast::Ast, attribute::Attribute, binding::Binding, - color::Color, color_display::ColorDisplay, command_color::CommandColor, - command_ext::CommandExt, compilation::Compilation, compile_error::CompileError, - compile_error_kind::CompileErrorKind, compiler::Compiler, condition::Condition, - conditional_operator::ConditionalOperator, config::Config, config_error::ConfigError, - constants::constants, count::Count, delimiter::Delimiter, dependency::Dependency, - dump_format::DumpFormat, enclosure::Enclosure, error::Error, evaluator::Evaluator, - execution_context::ExecutionContext, executor::Executor, expression::Expression, - fragment::Fragment, function::Function, interpreter::Interpreter, + alias::Alias, alias_style::AliasStyle, analyzer::Analyzer, argument_parser::ArgumentParser, + assignment::Assignment, assignment_resolver::AssignmentResolver, ast::Ast, + attribute::Attribute, binding::Binding, color::Color, color_display::ColorDisplay, + command_color::CommandColor, command_ext::CommandExt, compilation::Compilation, + compile_error::CompileError, compile_error_kind::CompileErrorKind, compiler::Compiler, + condition::Condition, conditional_operator::ConditionalOperator, config::Config, + config_error::ConfigError, constants::constants, count::Count, delimiter::Delimiter, + dependency::Dependency, dump_format::DumpFormat, enclosure::Enclosure, error::Error, + evaluator::Evaluator, execution_context::ExecutionContext, executor::Executor, + expression::Expression, fragment::Fragment, function::Function, interpreter::Interpreter, interrupt_guard::InterruptGuard, interrupt_handler::InterruptHandler, item::Item, justfile::Justfile, keyed::Keyed, keyword::Keyword, lexer::Lexer, line::Line, list::List, load_dotenv::load_dotenv, loader::Loader, module_path::ModulePath, name::Name, @@ -107,6 +107,7 @@ pub mod fuzzing; pub mod summary; mod alias; +mod alias_style; mod analyzer; mod argument_parser; mod assignment; diff --git a/src/subcommand.rs b/src/subcommand.rs index e5ea287972..687a7a3eb4 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -414,7 +414,7 @@ impl Subcommand { ) { let doc = doc.unwrap_or_default(); let print_doc = !doc.is_empty() && doc.lines().count() <= 1; - let print_aliases = !config.no_inline_aliases && !aliases.is_empty(); + let print_aliases = config.alias_style != AliasStyle::Recipe && !aliases.is_empty(); if print_doc || print_aliases { print!( @@ -435,7 +435,7 @@ impl Subcommand { .paint(&format!("[aliases: {}]", aliases.join(", "))) )); - let (left, right) = if config.inline_aliases_left { + let (left, right) = if config.alias_style == AliasStyle::InlineLeft { (aliases, doc) } else { (doc, aliases) @@ -574,7 +574,7 @@ impl Subcommand { if let Some(recipes) = recipe_groups.get(&group) { for recipe in recipes { - let recipe_alias_entries = if config.no_inline_aliases { + let recipe_alias_entries = if config.alias_style == AliasStyle::Recipe { aliases.get(recipe.name()) } else { None diff --git a/tests/alias_style.rs b/tests/alias_style.rs new file mode 100644 index 0000000000..1b2f94b286 --- /dev/null +++ b/tests/alias_style.rs @@ -0,0 +1,60 @@ +use super::*; + +#[test] +fn alias_style_inline() { + Test::new() + .justfile( + " + alias t := test1 + + # A test recipe + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--alias-style=inline", "--list"]) + .stdout("Available recipes:\n test1 # A test recipe [aliases: t]\n test2\n") + .run(); +} + +#[test] +fn alias_style_inline_left() { + Test::new() + .justfile( + " + alias t := test1 + + # A test recipe + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--alias-style=inline-left", "--list"]) + .stdout("Available recipes:\n test1 # [aliases: t] A test recipe\n test2\n") + .run(); +} + +#[test] +fn alias_style_recipe() { + Test::new() + .justfile( + " + alias t := test1 + + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--alias-style=recipe", "--list"]) + .stdout("Available recipes:\n test1\n t # alias for `test1`\n test2\n") + .run(); +} diff --git a/tests/lib.rs b/tests/lib.rs index 0bb48212e8..dfa11fc352 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -31,6 +31,7 @@ pub(crate) use { #[macro_use] mod test; +mod alias_style; mod allow_duplicate_recipes; mod allow_duplicate_variables; mod assert_stdout; @@ -82,7 +83,6 @@ mod no_aliases; mod no_cd; mod no_dependencies; mod no_exit_message; -mod no_inline_aliases; mod os_attributes; mod parameters; mod parser; diff --git a/tests/list.rs b/tests/list.rs index 5190c3d31c..db7b669e44 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -438,23 +438,3 @@ fn no_space_before_submodules_not_following_groups() { ) .run(); } - -#[test] -fn inline_aliases_left_flag() { - Test::new() - .justfile( - " - alias t := test1 - - # I'm a recipe - test1: - @echo 'test1' - - test2: - @echo 'test2' - ", - ) - .args(["--inline-aliases-left", "--list"]) - .stdout("Available recipes:\n test1 # [aliases: t] I'm a recipe\n test2\n") - .run(); -} diff --git a/tests/no_inline_aliases.rs b/tests/no_inline_aliases.rs deleted file mode 100644 index 4194933777..0000000000 --- a/tests/no_inline_aliases.rs +++ /dev/null @@ -1,20 +0,0 @@ -use super::*; - -#[test] -fn no_inline_aliases_flag() { - Test::new() - .justfile( - " - alias t := test1 - - test1: - @echo 'test1' - - test2: - @echo 'test2' - ", - ) - .args(["--no-inline-aliases", "--list"]) - .stdout("Available recipes:\n test1\n t # alias for `test1`\n test2\n") - .run(); -}