Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion completions/just.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _just() {

case "${cmd}" in
just)
opts="-E -n -g -f -q -u -v -d -c -e -l -s -h -V --alias-style --ceiling --check --chooser --clear-shell-args --color --command-color --cygpath --dotenv-filename --dotenv-path --dry-run --dump-format --explain --global-justfile --highlight --justfile --list-heading --list-prefix --list-submodules --no-aliases --no-deps --no-dotenv --no-highlight --one --quiet --allow-missing --set --shell --shell-arg --shell-command --tempdir --timestamp --timestamp-format --unsorted --unstable --verbose --working-directory --yes --changelog --choose --command --completions --dump --edit --evaluate --fmt --groups --init --list --man --request --show --summary --usage --variables --help --version [ARGUMENTS]..."
opts="-E -n -g -f -q -u -v -d -c -e -l -s -h -V --alias-style --ceiling --check --chooser --clear-shell-args --color --command-color --cygpath --dotenv-filename --dotenv-path --dry-run --dump-format --explain --global-justfile --highlight --justfile --list-heading --list-prefix --list-submodules --group --no-aliases --no-deps --no-dotenv --no-highlight --one --quiet --allow-missing --set --shell --shell-arg --shell-command --tempdir --timestamp --timestamp-format --unsorted --unstable --verbose --working-directory --yes --changelog --choose --command --completions --dump --edit --evaluate --fmt --groups --init --list --man --request --show --summary --usage --variables --help --version [ARGUMENTS]..."
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -108,6 +108,10 @@ _just() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--group)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--set)
COMPREPLY=($(compgen -f "${cur}"))
return 0
Expand Down
1 change: 1 addition & 0 deletions completions/just.elvish
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set edit:completion:arg-completer[just] = {|@words|
cand --justfile 'Use <JUSTFILE> as justfile'
cand --list-heading 'Print <TEXT> before list'
cand --list-prefix 'Print <TEXT> before each list item'
cand --group 'Only list recipes in <GROUP>'
cand --set 'Override <VARIABLE> with <VALUE>'
cand --shell 'Invoke <SHELL> to run recipes'
cand --shell-arg 'Invoke shell with <SHELL-ARG> as an argument'
Expand Down
1 change: 1 addition & 0 deletions completions/just.fish
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ just\t''"
complete -c just -s f -l justfile -d 'Use <JUSTFILE> as justfile' -r -F
complete -c just -l list-heading -d 'Print <TEXT> before list' -r
complete -c just -l list-prefix -d 'Print <TEXT> before each list item' -r
complete -c just -l group -d 'Only list recipes in <GROUP>' -r
complete -c just -l set -d 'Override <VARIABLE> with <VALUE>' -r
complete -c just -l shell -d 'Invoke <SHELL> to run recipes' -r
complete -c just -l shell-arg -d 'Invoke shell with <SHELL-ARG> as an argument' -r
Expand Down
1 change: 1 addition & 0 deletions completions/just.powershell
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {
[CompletionResult]::new('--justfile', '--justfile', [CompletionResultType]::ParameterName, 'Use <JUSTFILE> as justfile')
[CompletionResult]::new('--list-heading', '--list-heading', [CompletionResultType]::ParameterName, 'Print <TEXT> before list')
[CompletionResult]::new('--list-prefix', '--list-prefix', [CompletionResultType]::ParameterName, 'Print <TEXT> before each list item')
[CompletionResult]::new('--group', '--group', [CompletionResultType]::ParameterName, 'Only list recipes in <GROUP>')
[CompletionResult]::new('--set', '--set', [CompletionResultType]::ParameterName, 'Override <VARIABLE> with <VALUE>')
[CompletionResult]::new('--shell', '--shell', [CompletionResultType]::ParameterName, 'Invoke <SHELL> to run recipes')
[CompletionResult]::new('--shell-arg', '--shell-arg', [CompletionResultType]::ParameterName, 'Invoke shell with <SHELL-ARG> as an argument')
Expand Down
1 change: 1 addition & 0 deletions completions/just.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ _just() {
'--justfile=[Use <JUSTFILE> as justfile]: :_files' \
'--list-heading=[Print <TEXT> before list]:TEXT:_default' \
'--list-prefix=[Print <TEXT> before each list item]:TEXT:_default' \
'*--group=[Only list recipes in <GROUP>]:GROUP:_default' \
'*--set=[Override <VARIABLE> with <VALUE>]: :(_just_variables)' \
'--shell=[Invoke <SHELL> to run recipes]: :_default' \
'*--shell-arg=[Invoke shell with <SHELL-ARG> as an argument]: :_default' \
Expand Down
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub(crate) struct Config {
pub(crate) explain: bool,
pub(crate) highlight: bool,
pub(crate) invocation_directory: PathBuf,
pub(crate) list_groups: Vec<String>,
Comment thread
terror marked this conversation as resolved.
Outdated
pub(crate) list_heading: String,
pub(crate) list_prefix: String,
pub(crate) list_submodules: bool,
Expand Down Expand Up @@ -110,6 +111,7 @@ mod arg {
pub(crate) const GLOBAL_JUSTFILE: &str = "GLOBAL-JUSTFILE";
pub(crate) const HIGHLIGHT: &str = "HIGHLIGHT";
pub(crate) const JUSTFILE: &str = "JUSTFILE";
pub(crate) const LIST_GROUP: &str = "LIST-GROUP";
Comment thread
terror marked this conversation as resolved.
Outdated
pub(crate) const LIST_HEADING: &str = "LIST-HEADING";
pub(crate) const LIST_PREFIX: &str = "LIST-PREFIX";
pub(crate) const LIST_SUBMODULES: &str = "LIST-SUBMODULES";
Expand Down Expand Up @@ -316,6 +318,15 @@ impl Config {
.action(ArgAction::SetTrue)
.requires(cmd::LIST),
)
.arg(
Arg::new(arg::LIST_GROUP)
Comment thread
terror marked this conversation as resolved.
Outdated
.long("group")
.env("JUST_GROUP")
.help("Only list recipes in <GROUP>")
.value_name("GROUP")
Comment thread
terror marked this conversation as resolved.
Outdated
.action(ArgAction::Append)
.requires(cmd::LIST),
)
.arg(
Arg::new(arg::NO_ALIASES)
.long("no-aliases")
Expand Down Expand Up @@ -827,6 +838,10 @@ impl Config {
explain,
highlight: !matches.get_flag(arg::NO_HIGHLIGHT),
invocation_directory: env::current_dir().context(config_error::CurrentDirContext)?,
list_groups: matches
.get_many::<String>(arg::LIST_GROUP)
.map(|s| s.map(Into::into).collect())
.unwrap_or_default(),
list_heading: matches.get_one::<String>(arg::LIST_HEADING).unwrap().into(),
list_prefix: matches.get_one::<String>(arg::LIST_PREFIX).unwrap().into(),
list_submodules: matches.get_flag(arg::LIST_SUBMODULES),
Expand Down
27 changes: 20 additions & 7 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,17 +634,30 @@ impl Subcommand {
groups
};

let mut ordered_groups = module
.public_groups(config)
.into_iter()
.map(Some)
.collect::<Vec<Option<String>>>();
let mut ordered_groups = if config.list_groups.is_empty() {
module
.public_groups(config)
.into_iter()
.map(Some)
.collect::<Vec<Option<String>>>()
} else {
config
.list_groups
.iter()
.cloned()
.map(Some)
.collect::<Vec<Option<String>>>()
};

if recipe_groups.contains_key(&None) || submodule_groups.contains_key(&None) {
if config.list_groups.is_empty()
&& (recipe_groups.contains_key(&None) || submodule_groups.contains_key(&None))
{
ordered_groups.insert(0, None);
}

let no_groups = ordered_groups.len() == 1 && ordered_groups.first() == Some(&None);
let no_groups = config.list_groups.is_empty()
&& ordered_groups.len() == 1
&& ordered_groups.first() == Some(&None);

let groups_count = if no_groups { 0 } else { ordered_groups.len() };

Expand Down
58 changes: 58 additions & 0 deletions tests/groups.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
use super::*;

#[test]
fn list_group() {
Test::new()
.justfile(
"
[group('alpha')]
a:
[group('alpha')]
[group('beta')]
b:
c:
[group('beta')]
d:
",
)
.args(["--list", "--group", "alpha"])
.stdout(
"
Available recipes:
[alpha]
a
b
",
)
.success();
}

#[test]
fn list_multiple_groups() {
Test::new()
.justfile(
"
[group('alpha')]
a:
[group('alpha')]
[group('beta')]
b:
c:
[group('beta')]
d:
",
)
.args(["--list", "--group", "alpha", "--group", "beta"])
.stdout(
"
Available recipes:
[alpha]
a
b

[beta]
b
d
",
)
.success();
}

#[test]
fn list_with_groups() {
Test::new()
Expand Down