Skip to content

Commit

Permalink
Add --changelog subcommand (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jul 31, 2021
1 parent 9c3bbc9 commit 5bb4b4a
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,10 @@ default:
echo foo
```

=== Changelog

A changelog for the latest release is available in link:CHANGELOG.md[]. Changelogs for previous releases are avaiable on https://github.com/casey/just/releases[the releases page]. `just --changelog` can also be used to make a `just` binary print its changelog.

== Miscellanea

=== Companion Tools
Expand Down
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 -u -v -e -l -h -V -f -d -c -s --dry-run --highlight --no-dotenv --no-highlight --quiet --shell-command --clear-shell-args --unsorted --unstable --verbose --choose --dump --edit --evaluate --fmt --init --list --summary --variables --help --version --chooser --color --list-heading --list-prefix --justfile --set --shell --shell-arg --working-directory --command --completions --show <ARGUMENTS>... "
opts=" -q -u -v -e -l -h -V -f -d -c -s --dry-run --highlight --no-dotenv --no-highlight --quiet --shell-command --clear-shell-args --unsorted --unstable --verbose --changelog --choose --dump --edit --evaluate --fmt --init --list --summary --variables --help --version --chooser --color --list-heading --list-prefix --justfile --set --shell --shell-arg --working-directory --command --completions --show <ARGUMENTS>... "
if [[ ${cur} == -* ]] ; 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 @@ -43,6 +43,7 @@ edit:completion:arg-completer[just] = [@words]{
cand --unstable 'Enable unstable features'
cand -v 'Use verbose output'
cand --verbose 'Use verbose output'
cand --changelog 'Print changelog'
cand --choose 'Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
cand --dump 'Print entire justfile'
cand -e 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
Expand Down
1 change: 1 addition & 0 deletions completions/just.fish
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ complete -c just -n "__fish_use_subcommand" -l clear-shell-args -d 'Clear shell
complete -c just -n "__fish_use_subcommand" -s u -l unsorted -d 'Return list and summary entries in source order'
complete -c just -n "__fish_use_subcommand" -l unstable -d 'Enable unstable features'
complete -c just -n "__fish_use_subcommand" -s v -l verbose -d 'Use verbose output'
complete -c just -n "__fish_use_subcommand" -l changelog -d 'Print changelog'
complete -c just -n "__fish_use_subcommand" -l choose -d 'Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
complete -c just -n "__fish_use_subcommand" -l dump -d 'Print entire justfile'
complete -c just -n "__fish_use_subcommand" -s e -l edit -d 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
Expand Down
1 change: 1 addition & 0 deletions completions/just.powershell
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {
[CompletionResult]::new('--unstable', 'unstable', [CompletionResultType]::ParameterName, 'Enable unstable features')
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Use verbose output')
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Use verbose output')
[CompletionResult]::new('--changelog', 'changelog', [CompletionResultType]::ParameterName, 'Print changelog')
[CompletionResult]::new('--choose', 'choose', [CompletionResultType]::ParameterName, 'Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`')
[CompletionResult]::new('--dump', 'dump', [CompletionResultType]::ParameterName, 'Print entire justfile')
[CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`')
Expand Down
1 change: 1 addition & 0 deletions completions/just.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ _just() {
'--unstable[Enable unstable features]' \
'*-v[Use verbose output]' \
'*--verbose[Use verbose output]' \
'--changelog[Print changelog]' \
'--choose[Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`]' \
'--dump[Print entire justfile]' \
'-e[Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`]' \
Expand Down
30 changes: 28 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ pub(crate) struct Config {
}

mod cmd {
pub(crate) const CHANGELOG: &str = "CHANGELOG";
pub(crate) const CHOOSE: &str = "CHOOSE";
pub(crate) const COMMAND: &str = "COMMAND";
pub(crate) const COMPLETIONS: &str = "COMPLETIONS";
pub(crate) const DUMP: &str = "DUMP";
pub(crate) const EDIT: &str = "EDIT";
Expand All @@ -44,9 +46,9 @@ mod cmd {
pub(crate) const SHOW: &str = "SHOW";
pub(crate) const SUMMARY: &str = "SUMMARY";
pub(crate) const VARIABLES: &str = "VARIABLES";
pub(crate) const COMMAND: &str = "COMMAND";

pub(crate) const ALL: &[&str] = &[
CHANGELOG,
CHOOSE,
COMMAND,
COMPLETIONS,
Expand All @@ -62,6 +64,7 @@ mod cmd {
];

pub(crate) const ARGLESS: &[&str] = &[
CHANGELOG,
COMPLETIONS,
DUMP,
EDIT,
Expand Down Expand Up @@ -239,6 +242,11 @@ impl Config {
.help("Use <WORKING-DIRECTORY> as working directory. --justfile must also be set")
.requires(arg::JUSTFILE),
)
.arg(
Arg::with_name(cmd::CHANGELOG)
.long("changelog")
.help("Print changelog"),
)
.arg(Arg::with_name(cmd::CHOOSE).long("choose").help(CHOOSE_HELP))
.arg(
Arg::with_name(cmd::COMMAND)
Expand Down Expand Up @@ -431,7 +439,9 @@ impl Config {
}
}

let subcommand = if matches.is_present(cmd::CHOOSE) {
let subcommand = if matches.is_present(cmd::CHANGELOG) {
Subcommand::Changelog
} else if matches.is_present(cmd::CHOOSE) {
Subcommand::Choose {
chooser: matches.value_of(arg::CHOOSER).map(str::to_owned),
overrides,
Expand Down Expand Up @@ -565,6 +575,7 @@ USAGE:
just [FLAGS] [OPTIONS] [--] [ARGUMENTS]...
FLAGS:
--changelog Print changelog
--choose Select one or more recipes to run using a binary. If `--chooser` is \
not passed the chooser
defaults to the value of $JUST_CHOOSER, falling back to `fzf`
Expand Down Expand Up @@ -963,6 +974,11 @@ ARGS:
},
}

error! {
name: subcommand_conflict_changelog,
args: ["--list", "--changelog"],
}

error! {
name: subcommand_conflict_summary,
args: ["--list", "--summary"],
Expand Down Expand Up @@ -1294,6 +1310,16 @@ ARGS:
},
}

error! {
name: changelog_arguments,
args: ["--changelog", "bar"],
error: ConfigError::SubcommandArguments { subcommand, arguments },
check: {
assert_eq!(subcommand, cmd::CHANGELOG);
assert_eq!(arguments, &["bar"]);
},
}

error! {
name: list_arguments,
args: ["--list", "bar"],
Expand Down
21 changes: 14 additions & 7 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const INIT_JUSTFILE: &str = "default:\n\techo 'Hello, world!'\n";

#[derive(PartialEq, Clone, Debug)]
pub(crate) enum Subcommand {
Changelog,
Choose {
overrides: BTreeMap<String, String>,
chooser: Option<String>,
Expand Down Expand Up @@ -40,12 +41,14 @@ impl Subcommand {
pub(crate) fn run<'src>(&self, config: &Config, loader: &'src Loader) -> Result<(), Error<'src>> {
use Subcommand::*;

if let Init = self {
return Self::init(config);
}

if let Completions { shell } = self {
return Self::completions(&shell);
match self {
Changelog => {
Self::changelog();
return Ok(());
},
Completions { shell } => return Self::completions(&shell),
Init => return Self::init(config),
_ => {},
}

let search = Search::find(&config.search_config, &config.invocation_directory)?;
Expand Down Expand Up @@ -81,12 +84,16 @@ impl Subcommand {
Show { ref name } => Self::show(config, &name, justfile)?,
Summary => Self::summary(config, justfile),
Variables => Self::variables(justfile),
Completions { .. } | Edit | Init => unreachable!(),
Changelog | Completions { .. } | Edit | Init => unreachable!(),
}

Ok(())
}

fn changelog() {
print!("{}", include_str!("../CHANGELOG.md"));
}

fn choose<'src>(
config: &Config,
justfile: Justfile<'src>,
Expand Down
9 changes: 9 additions & 0 deletions tests/changelog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::common::*;

#[test]
fn print_changelog() {
Test::new()
.args(&["--changelog"])
.stdout(fs::read_to_string("CHANGELOG.md").unwrap())
.run();
}
2 changes: 1 addition & 1 deletion tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test! {
USAGE:
just{} --color <COLOR> --shell <SHELL> --shell-arg <SHELL-ARG>... \
<--choose|--command <COMMAND>|--completions <SHELL>|--dump|--edit|\
<--changelog|--choose|--command <COMMAND>|--completions <SHELL>|--dump|--edit|\
--evaluate|--fmt|--init|--list|--show <RECIPE>|--summary|--variables>
For more information try --help
Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod test;

mod assert_stdout;
mod assert_success;
mod changelog;
mod choose;
mod command;
mod common;
Expand Down

0 comments on commit 5bb4b4a

Please sign in to comment.