Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --variables subcommand that prints variable names #608

Merged
merged 1 commit into from
Mar 14, 2020
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
5 changes: 1 addition & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ jobs:
- name: Completion Scripts
if: matrix.os != 'windows-latest'
run: |
for script in completions/*; do
shell=${script##*.}
cargo run -- --completions $shell > $script
done
./bin/generate-completions
git diff --no-ext-diff --quiet --exit-code
- name: Package
id: package
Expand Down
155 changes: 73 additions & 82 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions bin/generate-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -euxo pipefail

for script in completions/*; do
shell=${script##*.}
cargo run -- --completions $shell > $script
done
2 changes: 1 addition & 1 deletion completions/just.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _just() {

case "${cmd}" in
just)
opts=" -q -v -e -l -h -V -f -d -s --dry-run --highlight --no-highlight --quiet --clear-shell-args --verbose --dump --edit --evaluate --init --list --summary --help --version --color --justfile --set --shell --shell-arg --working-directory --completions --show <ARGUMENTS>... "
opts=" -q -v -e -l -h -V -f -d -s --dry-run --highlight --no-highlight --quiet --clear-shell-args --verbose --dump --edit --evaluate --init --list --summary --variables --help --version --color --justfile --set --shell --shell-arg --working-directory --completions --show <ARGUMENTS>... "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${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 @@ -42,6 +42,7 @@ edit:completion:arg-completer[just] = [@words]{
cand -l 'List available recipes and their arguments'
cand --list 'List available recipes and their arguments'
cand --summary 'List names of available recipes'
cand --variables 'List names of variables'
cand -h 'Print help information'
cand --help 'Print help information'
cand -V 'Print version information'
Expand Down
1 change: 1 addition & 0 deletions completions/just.fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ complete -c just -n "__fish_use_subcommand" -l evaluate -d 'Print evaluated vari
complete -c just -n "__fish_use_subcommand" -l init -d 'Initialize new justfile in project root'
complete -c just -n "__fish_use_subcommand" -s l -l list -d 'List available recipes and their arguments'
complete -c just -n "__fish_use_subcommand" -l summary -d 'List names of available recipes'
complete -c just -n "__fish_use_subcommand" -l variables -d 'List names of variables'
complete -c just -n "__fish_use_subcommand" -s h -l help -d 'Print help information'
complete -c just -n "__fish_use_subcommand" -s V -l version -d 'Print version information'
1 change: 1 addition & 0 deletions completions/just.powershell
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {
[CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'List available recipes and their arguments')
[CompletionResult]::new('--list', 'list', [CompletionResultType]::ParameterName, 'List available recipes and their arguments')
[CompletionResult]::new('--summary', 'summary', [CompletionResultType]::ParameterName, 'List names of available recipes')
[CompletionResult]::new('--variables', 'variables', [CompletionResultType]::ParameterName, 'List names of variables')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version information')
Expand Down
1 change: 1 addition & 0 deletions completions/just.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ _just() {
'-l[List available recipes and their arguments]' \
'--list[List available recipes and their arguments]' \
'--summary[List names of available recipes]' \
'--variables[List names of variables]' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ watch-readme:
just render-readme
fswatch -ro README.adoc | xargs -n1 -I{} just render-readme

generate-completions:
./bin/generate-completions

# run all polyglot recipes
polyglot: _python _js _perl _sh _ruby
# (recipes that start with `_` are hidden from --list)
Expand Down
51 changes: 46 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,38 @@ pub(crate) struct Config {
}

mod cmd {
pub(crate) const COMPLETIONS: &str = "COMPLETIONS";
pub(crate) const DUMP: &str = "DUMP";
pub(crate) const EDIT: &str = "EDIT";
pub(crate) const EVALUATE: &str = "EVALUATE";
pub(crate) const INIT: &str = "INIT";
pub(crate) const LIST: &str = "LIST";
pub(crate) const SHOW: &str = "SHOW";
pub(crate) const SUMMARY: &str = "SUMMARY";
pub(crate) const COMPLETIONS: &str = "COMPLETIONS";

pub(crate) const ALL: &[&str] = &[COMPLETIONS, DUMP, EDIT, INIT, EVALUATE, LIST, SHOW, SUMMARY];
pub(crate) const ARGLESS: &[&str] = &[COMPLETIONS, DUMP, EDIT, INIT, LIST, SHOW, SUMMARY];
pub(crate) const VARIABLES: &str = "VARIABLES";

pub(crate) const ALL: &[&str] = &[
COMPLETIONS,
DUMP,
EDIT,
INIT,
EVALUATE,
LIST,
SHOW,
SUMMARY,
VARIABLES,
];

pub(crate) const ARGLESS: &[&str] = &[
COMPLETIONS,
DUMP,
EDIT,
INIT,
LIST,
SHOW,
SUMMARY,
VARIABLES,
];
}

mod arg {
Expand Down Expand Up @@ -206,6 +227,11 @@ impl Config {
.long("summary")
.help("List names of available recipes"),
)
.arg(
Arg::with_name(cmd::VARIABLES)
.long("variables")
.help("List names of variables"),
)
.group(ArgGroup::with_name("SUBCOMMAND").args(cmd::ALL));

if cfg!(feature = "help4help2man") {
Expand Down Expand Up @@ -345,6 +371,8 @@ impl Config {
});
}
Subcommand::Evaluate { overrides }
} else if matches.is_present(cmd::VARIABLES) {
Subcommand::Variables
} else {
Subcommand::Run {
arguments: positional.arguments,
Expand Down Expand Up @@ -419,13 +447,14 @@ impl Config {
match &self.subcommand {
Dump => Self::dump(justfile),
Evaluate { overrides } => self.run(justfile, &search, overrides, &Vec::new()),
List => self.list(justfile),
Run {
arguments,
overrides,
} => self.run(justfile, &search, overrides, arguments),
List => self.list(justfile),
Show { ref name } => Self::show(&name, justfile),
Summary => Self::summary(justfile),
Variables => Self::variables(justfile),
Completions { .. } | Edit | Init => unreachable!(),
}
}
Expand Down Expand Up @@ -635,6 +664,17 @@ impl Config {
}
Ok(())
}

fn variables(justfile: Justfile) -> Result<(), i32> {
for (i, (_, assignment)) in justfile.assignments.iter().enumerate() {
if i > 0 {
print!(" ");
}
print!("{}", assignment.name)
}
println!();
Ok(())
}
}

#[cfg(test)]
Expand Down Expand Up @@ -668,6 +708,7 @@ FLAGS:
--no-highlight Don't highlight echoed recipe lines in bold
-q, --quiet Suppress all output
--summary List names of available recipes
--variables List names of variables
-v, --verbose Use verbose output

OPTIONS:
Expand Down
1 change: 1 addition & 0 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ pub(crate) enum Subcommand {
name: String,
},
Summary,
Variables,
}
12 changes: 12 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2459,3 +2459,15 @@ test! {
status: EXIT_SUCCESS,
shell: false,
}

test! {
name: variables,
justfile: "
z := 'a'
a := 'z'
",
args: ("--variables"),
stdout: "a z\n",
stderr: "",
shell: false,
}