2022-12-27 20:16:18 -08:00
|
|
|
use {
|
|
|
|
super::*,
|
|
|
|
clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, ArgSettings},
|
|
|
|
};
|
2019-10-07 02:06:45 -07:00
|
|
|
|
2020-09-17 19:43:04 -07:00
|
|
|
// These three strings should be kept in sync:
|
2023-06-12 10:06:51 -07:00
|
|
|
pub(crate) const CHOOSER_DEFAULT: &str = "fzf --multi --preview 'just --show {}'";
|
2020-09-17 19:43:04 -07:00
|
|
|
pub(crate) const CHOOSER_ENVIRONMENT_KEY: &str = "JUST_CHOOSER";
|
2020-10-10 17:54:58 -07:00
|
|
|
pub(crate) const CHOOSE_HELP: &str = "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`";
|
2020-09-17 19:43:04 -07:00
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
#[derive(Debug, PartialEq)]
|
2023-06-12 09:53:55 -07:00
|
|
|
#[allow(clippy::struct_excessive_bools)]
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
pub(crate) struct Config {
|
2021-10-31 21:27:59 -07:00
|
|
|
pub(crate) check: bool,
|
2021-11-17 00:07:48 -08:00
|
|
|
pub(crate) color: Color,
|
2023-10-10 17:04:34 -07:00
|
|
|
pub(crate) command_color: Option<ansi_term::Color>,
|
2021-11-17 00:07:48 -08:00
|
|
|
pub(crate) dotenv_filename: Option<String>,
|
|
|
|
pub(crate) dotenv_path: Option<PathBuf>,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) dry_run: bool,
|
2021-11-17 00:07:48 -08:00
|
|
|
pub(crate) dump_format: DumpFormat,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) highlight: bool,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
pub(crate) invocation_directory: PathBuf,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) list_heading: String,
|
|
|
|
pub(crate) list_prefix: String,
|
|
|
|
pub(crate) load_dotenv: bool,
|
|
|
|
pub(crate) search_config: SearchConfig,
|
2022-01-18 11:02:15 -08:00
|
|
|
pub(crate) shell: Option<String>,
|
|
|
|
pub(crate) shell_args: Option<Vec<String>>,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) shell_command: bool,
|
|
|
|
pub(crate) subcommand: Subcommand,
|
|
|
|
pub(crate) unsorted: bool,
|
|
|
|
pub(crate) unstable: bool,
|
|
|
|
pub(crate) verbosity: Verbosity,
|
2019-10-07 02:06:45 -07:00
|
|
|
}
|
|
|
|
|
2019-10-31 17:39:25 -07:00
|
|
|
mod cmd {
|
2021-07-31 13:53:27 -07:00
|
|
|
pub(crate) const CHANGELOG: &str = "CHANGELOG";
|
2020-09-17 19:43:04 -07:00
|
|
|
pub(crate) const CHOOSE: &str = "CHOOSE";
|
2021-07-31 13:53:27 -07:00
|
|
|
pub(crate) const COMMAND: &str = "COMMAND";
|
2020-03-13 22:19:43 -07:00
|
|
|
pub(crate) const COMPLETIONS: &str = "COMPLETIONS";
|
2019-10-07 04:04:39 -07:00
|
|
|
pub(crate) const DUMP: &str = "DUMP";
|
2019-10-09 00:18:53 -07:00
|
|
|
pub(crate) const EDIT: &str = "EDIT";
|
2019-10-31 17:39:25 -07:00
|
|
|
pub(crate) const EVALUATE: &str = "EVALUATE";
|
2021-06-08 01:01:27 -07:00
|
|
|
pub(crate) const FORMAT: &str = "FORMAT";
|
2019-11-19 23:07:44 -08:00
|
|
|
pub(crate) const INIT: &str = "INIT";
|
2019-10-07 04:04:39 -07:00
|
|
|
pub(crate) const LIST: &str = "LIST";
|
|
|
|
pub(crate) const SHOW: &str = "SHOW";
|
2019-10-09 00:18:53 -07:00
|
|
|
pub(crate) const SUMMARY: &str = "SUMMARY";
|
2020-03-13 22:19:43 -07:00
|
|
|
pub(crate) const VARIABLES: &str = "VARIABLES";
|
|
|
|
|
|
|
|
pub(crate) const ALL: &[&str] = &[
|
2021-07-31 13:53:27 -07:00
|
|
|
CHANGELOG,
|
2020-09-17 19:43:04 -07:00
|
|
|
CHOOSE,
|
2021-05-09 20:35:35 -07:00
|
|
|
COMMAND,
|
2020-03-13 22:19:43 -07:00
|
|
|
COMPLETIONS,
|
|
|
|
DUMP,
|
|
|
|
EDIT,
|
|
|
|
EVALUATE,
|
2021-06-08 01:01:27 -07:00
|
|
|
FORMAT,
|
2021-05-09 20:35:35 -07:00
|
|
|
INIT,
|
2020-03-13 22:19:43 -07:00
|
|
|
LIST,
|
|
|
|
SHOW,
|
|
|
|
SUMMARY,
|
|
|
|
VARIABLES,
|
|
|
|
];
|
|
|
|
|
|
|
|
pub(crate) const ARGLESS: &[&str] = &[
|
2021-07-31 13:53:27 -07:00
|
|
|
CHANGELOG,
|
2020-03-13 22:19:43 -07:00
|
|
|
COMPLETIONS,
|
|
|
|
DUMP,
|
|
|
|
EDIT,
|
2021-06-08 01:01:27 -07:00
|
|
|
FORMAT,
|
2020-03-13 22:19:43 -07:00
|
|
|
INIT,
|
|
|
|
LIST,
|
|
|
|
SHOW,
|
|
|
|
SUMMARY,
|
|
|
|
VARIABLES,
|
|
|
|
];
|
2019-10-31 17:39:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mod arg {
|
|
|
|
pub(crate) const ARGUMENTS: &str = "ARGUMENTS";
|
2021-10-31 21:27:59 -07:00
|
|
|
pub(crate) const CHECK: &str = "CHECK";
|
2020-09-17 19:43:04 -07:00
|
|
|
pub(crate) const CHOOSER: &str = "CHOOSER";
|
2019-11-22 11:33:56 -08:00
|
|
|
pub(crate) const CLEAR_SHELL_ARGS: &str = "CLEAR-SHELL-ARGS";
|
2019-10-31 17:39:25 -07:00
|
|
|
pub(crate) const COLOR: &str = "COLOR";
|
2023-10-10 17:04:34 -07:00
|
|
|
pub(crate) const COMMAND_COLOR: &str = "COMMAND-COLOR";
|
2021-11-17 00:07:48 -08:00
|
|
|
pub(crate) const DOTENV_FILENAME: &str = "DOTENV-FILENAME";
|
|
|
|
pub(crate) const DOTENV_PATH: &str = "DOTENV-PATH";
|
2019-10-31 17:39:25 -07:00
|
|
|
pub(crate) const DRY_RUN: &str = "DRY-RUN";
|
2021-11-17 00:07:48 -08:00
|
|
|
pub(crate) const DUMP_FORMAT: &str = "DUMP-FORMAT";
|
2019-10-31 17:39:25 -07:00
|
|
|
pub(crate) const HIGHLIGHT: &str = "HIGHLIGHT";
|
2021-05-09 20:35:35 -07:00
|
|
|
pub(crate) const JUSTFILE: &str = "JUSTFILE";
|
2021-02-09 01:00:04 -08:00
|
|
|
pub(crate) const LIST_HEADING: &str = "LIST-HEADING";
|
|
|
|
pub(crate) const LIST_PREFIX: &str = "LIST-PREFIX";
|
2020-05-23 20:41:12 -07:00
|
|
|
pub(crate) const NO_DOTENV: &str = "NO-DOTENV";
|
2019-11-22 11:33:56 -08:00
|
|
|
pub(crate) const NO_HIGHLIGHT: &str = "NO-HIGHLIGHT";
|
2019-10-31 17:39:25 -07:00
|
|
|
pub(crate) const QUIET: &str = "QUIET";
|
|
|
|
pub(crate) const SET: &str = "SET";
|
|
|
|
pub(crate) const SHELL: &str = "SHELL";
|
2019-11-22 11:33:56 -08:00
|
|
|
pub(crate) const SHELL_ARG: &str = "SHELL-ARG";
|
2021-05-09 20:35:35 -07:00
|
|
|
pub(crate) const SHELL_COMMAND: &str = "SHELL-COMMAND";
|
2020-08-21 15:13:54 -07:00
|
|
|
pub(crate) const UNSORTED: &str = "UNSORTED";
|
2021-06-12 15:34:41 -07:00
|
|
|
pub(crate) const UNSTABLE: &str = "UNSTABLE";
|
2019-10-31 17:39:25 -07:00
|
|
|
pub(crate) const VERBOSE: &str = "VERBOSE";
|
2019-10-09 00:18:53 -07:00
|
|
|
pub(crate) const WORKING_DIRECTORY: &str = "WORKING-DIRECTORY";
|
|
|
|
|
|
|
|
pub(crate) const COLOR_ALWAYS: &str = "always";
|
2019-10-31 17:39:25 -07:00
|
|
|
pub(crate) const COLOR_AUTO: &str = "auto";
|
2019-10-09 00:18:53 -07:00
|
|
|
pub(crate) const COLOR_NEVER: &str = "never";
|
|
|
|
pub(crate) const COLOR_VALUES: &[&str] = &[COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER];
|
2021-11-17 00:07:48 -08:00
|
|
|
|
2023-10-10 17:04:34 -07:00
|
|
|
pub(crate) const COMMAND_COLOR_BLACK: &str = "black";
|
|
|
|
pub(crate) const COMMAND_COLOR_BLUE: &str = "blue";
|
|
|
|
pub(crate) const COMMAND_COLOR_CYAN: &str = "cyan";
|
|
|
|
pub(crate) const COMMAND_COLOR_GREEN: &str = "green";
|
|
|
|
pub(crate) const COMMAND_COLOR_PURPLE: &str = "purple";
|
|
|
|
pub(crate) const COMMAND_COLOR_RED: &str = "red";
|
|
|
|
pub(crate) const COMMAND_COLOR_YELLOW: &str = "yellow";
|
|
|
|
pub(crate) const COMMAND_COLOR_VALUES: &[&str] = &[
|
|
|
|
COMMAND_COLOR_BLACK,
|
|
|
|
COMMAND_COLOR_BLUE,
|
|
|
|
COMMAND_COLOR_CYAN,
|
|
|
|
COMMAND_COLOR_GREEN,
|
|
|
|
COMMAND_COLOR_PURPLE,
|
|
|
|
COMMAND_COLOR_RED,
|
|
|
|
COMMAND_COLOR_YELLOW,
|
|
|
|
];
|
|
|
|
|
2021-11-17 00:07:48 -08:00
|
|
|
pub(crate) const DUMP_FORMAT_JSON: &str = "json";
|
|
|
|
pub(crate) const DUMP_FORMAT_JUST: &str = "just";
|
|
|
|
pub(crate) const DUMP_FORMAT_VALUES: &[&str] = &[DUMP_FORMAT_JUST, DUMP_FORMAT_JSON];
|
2019-10-07 04:04:39 -07:00
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
impl Config {
|
2019-10-07 02:06:45 -07:00
|
|
|
pub(crate) fn app() -> App<'static, 'static> {
|
|
|
|
let app = App::new(env!("CARGO_PKG_NAME"))
|
|
|
|
.help_message("Print help information")
|
|
|
|
.version_message("Print version information")
|
|
|
|
.setting(AppSettings::ColoredHelp)
|
|
|
|
.setting(AppSettings::TrailingVarArg)
|
2021-10-31 21:27:59 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::CHECK)
|
|
|
|
.long("check")
|
|
|
|
.requires(cmd::FORMAT)
|
|
|
|
.help("Run `--fmt` in 'check' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required."),
|
|
|
|
)
|
2020-09-17 19:43:04 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::CHOOSER)
|
|
|
|
.long("chooser")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Override binary invoked by `--choose`"),
|
|
|
|
)
|
2019-10-07 02:06:45 -07:00
|
|
|
.arg(
|
2019-10-09 00:18:53 -07:00
|
|
|
Arg::with_name(arg::COLOR)
|
2019-10-07 02:06:45 -07:00
|
|
|
.long("color")
|
|
|
|
.takes_value(true)
|
2019-10-09 00:18:53 -07:00
|
|
|
.possible_values(arg::COLOR_VALUES)
|
|
|
|
.default_value(arg::COLOR_AUTO)
|
2019-10-07 02:06:45 -07:00
|
|
|
.help("Print colorful output"),
|
|
|
|
)
|
2023-10-10 17:04:34 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::COMMAND_COLOR)
|
|
|
|
.long("command-color")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(arg::COMMAND_COLOR_VALUES)
|
|
|
|
.help("Echo recipe lines in <COMMAND-COLOR>"),
|
|
|
|
)
|
2019-10-07 02:06:45 -07:00
|
|
|
.arg(
|
2019-10-31 17:39:25 -07:00
|
|
|
Arg::with_name(arg::DRY_RUN)
|
2023-01-23 23:48:30 -08:00
|
|
|
.short("n")
|
2019-10-07 02:06:45 -07:00
|
|
|
.long("dry-run")
|
|
|
|
.help("Print what just would do without doing it")
|
2019-10-31 17:39:25 -07:00
|
|
|
.conflicts_with(arg::QUIET),
|
2019-10-07 02:06:45 -07:00
|
|
|
)
|
2021-11-17 00:07:48 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::DUMP_FORMAT)
|
|
|
|
.long("dump-format")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(arg::DUMP_FORMAT_VALUES)
|
|
|
|
.default_value(arg::DUMP_FORMAT_JUST)
|
|
|
|
.value_name("FORMAT")
|
|
|
|
.help("Dump justfile as <FORMAT>"),
|
|
|
|
)
|
2019-10-07 02:06:45 -07:00
|
|
|
.arg(
|
2019-10-31 17:39:25 -07:00
|
|
|
Arg::with_name(arg::HIGHLIGHT)
|
2019-10-07 02:06:45 -07:00
|
|
|
.long("highlight")
|
2019-11-07 11:50:11 -08:00
|
|
|
.help("Highlight echoed recipe lines in bold")
|
|
|
|
.overrides_with(arg::NO_HIGHLIGHT),
|
|
|
|
)
|
2021-02-09 01:00:04 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::LIST_HEADING)
|
|
|
|
.long("list-heading")
|
|
|
|
.help("Print <TEXT> before list")
|
|
|
|
.value_name("TEXT")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::LIST_PREFIX)
|
|
|
|
.long("list-prefix")
|
|
|
|
.help("Print <TEXT> before each list item")
|
|
|
|
.value_name("TEXT")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2020-05-23 20:41:12 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::NO_DOTENV)
|
|
|
|
.long("no-dotenv")
|
|
|
|
.help("Don't load `.env` file"),
|
|
|
|
)
|
2019-11-07 11:50:11 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::NO_HIGHLIGHT)
|
|
|
|
.long("no-highlight")
|
|
|
|
.help("Don't highlight echoed recipe lines in bold")
|
|
|
|
.overrides_with(arg::HIGHLIGHT),
|
2019-10-07 02:06:45 -07:00
|
|
|
)
|
|
|
|
.arg(
|
2019-10-31 17:39:25 -07:00
|
|
|
Arg::with_name(arg::JUSTFILE)
|
2019-10-07 02:06:45 -07:00
|
|
|
.short("f")
|
|
|
|
.long("justfile")
|
|
|
|
.takes_value(true)
|
2021-02-09 01:00:04 -08:00
|
|
|
.help("Use <JUSTFILE> as justfile"),
|
2019-10-07 02:06:45 -07:00
|
|
|
)
|
|
|
|
.arg(
|
2019-10-31 17:39:25 -07:00
|
|
|
Arg::with_name(arg::QUIET)
|
2019-10-07 02:06:45 -07:00
|
|
|
.short("q")
|
|
|
|
.long("quiet")
|
|
|
|
.help("Suppress all output")
|
2019-10-31 17:39:25 -07:00
|
|
|
.conflicts_with(arg::DRY_RUN),
|
2019-10-07 02:06:45 -07:00
|
|
|
)
|
|
|
|
.arg(
|
2019-10-31 17:39:25 -07:00
|
|
|
Arg::with_name(arg::SET)
|
2019-10-07 02:06:45 -07:00
|
|
|
.long("set")
|
|
|
|
.takes_value(true)
|
|
|
|
.number_of_values(2)
|
|
|
|
.value_names(&["VARIABLE", "VALUE"])
|
|
|
|
.multiple(true)
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
.help("Override <VARIABLE> with <VALUE>"),
|
2019-10-07 02:06:45 -07:00
|
|
|
)
|
|
|
|
.arg(
|
2019-10-31 17:39:25 -07:00
|
|
|
Arg::with_name(arg::SHELL)
|
2019-10-07 02:06:45 -07:00
|
|
|
.long("shell")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Invoke <SHELL> to run recipes"),
|
|
|
|
)
|
2019-11-22 11:33:56 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::SHELL_ARG)
|
|
|
|
.long("shell-arg")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(true)
|
|
|
|
.number_of_values(1)
|
|
|
|
.allow_hyphen_values(true)
|
|
|
|
.overrides_with(arg::CLEAR_SHELL_ARGS)
|
|
|
|
.help("Invoke shell with <SHELL-ARG> as an argument"),
|
|
|
|
)
|
2021-05-09 20:35:35 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::SHELL_COMMAND)
|
|
|
|
.long("shell-command")
|
|
|
|
.requires(cmd::COMMAND)
|
|
|
|
.help("Invoke <COMMAND> with the shell used to run recipe lines and backticks"),
|
|
|
|
)
|
2019-11-22 11:33:56 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::CLEAR_SHELL_ARGS)
|
|
|
|
.long("clear-shell-args")
|
|
|
|
.overrides_with(arg::SHELL_ARG)
|
|
|
|
.help("Clear shell arguments"),
|
|
|
|
)
|
2020-08-21 15:13:54 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::UNSORTED)
|
|
|
|
.long("unsorted")
|
|
|
|
.short("u")
|
|
|
|
.help("Return list and summary entries in source order"),
|
|
|
|
)
|
2021-06-12 15:34:41 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::UNSTABLE)
|
|
|
|
.long("unstable")
|
|
|
|
.help("Enable unstable features"),
|
|
|
|
)
|
2019-10-07 02:06:45 -07:00
|
|
|
.arg(
|
2019-10-31 17:39:25 -07:00
|
|
|
Arg::with_name(arg::VERBOSE)
|
2019-10-07 02:06:45 -07:00
|
|
|
.short("v")
|
|
|
|
.long("verbose")
|
|
|
|
.multiple(true)
|
|
|
|
.help("Use verbose output"),
|
|
|
|
)
|
|
|
|
.arg(
|
2019-10-09 00:18:53 -07:00
|
|
|
Arg::with_name(arg::WORKING_DIRECTORY)
|
2019-10-07 02:06:45 -07:00
|
|
|
.short("d")
|
|
|
|
.long("working-directory")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Use <WORKING-DIRECTORY> as working directory. --justfile must also be set")
|
2019-10-31 17:39:25 -07:00
|
|
|
.requires(arg::JUSTFILE),
|
2019-10-07 02:06:45 -07:00
|
|
|
)
|
2021-07-31 13:53:27 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::CHANGELOG)
|
|
|
|
.long("changelog")
|
|
|
|
.help("Print changelog"),
|
|
|
|
)
|
2021-05-09 20:35:35 -07:00
|
|
|
.arg(Arg::with_name(cmd::CHOOSE).long("choose").help(CHOOSE_HELP))
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
.arg(
|
2021-05-09 20:35:35 -07:00
|
|
|
Arg::with_name(cmd::COMMAND)
|
|
|
|
.long("command")
|
|
|
|
.short("c")
|
|
|
|
.min_values(1)
|
|
|
|
.allow_hyphen_values(true)
|
|
|
|
.help(
|
|
|
|
"Run an arbitrary command with the working directory, `.env`, overrides, and exports \
|
|
|
|
set",
|
|
|
|
),
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
)
|
2020-01-15 01:20:38 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::COMPLETIONS)
|
|
|
|
.long("completions")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("SHELL")
|
|
|
|
.possible_values(&clap::Shell::variants())
|
|
|
|
.set(ArgSettings::CaseInsensitive)
|
|
|
|
.help("Print shell completion script for <SHELL>"),
|
|
|
|
)
|
2019-11-19 23:07:44 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::DUMP)
|
|
|
|
.long("dump")
|
2021-11-17 00:07:48 -08:00
|
|
|
.help("Print justfile"),
|
2019-11-19 23:07:44 -08:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::EDIT)
|
|
|
|
.short("e")
|
|
|
|
.long("edit")
|
|
|
|
.help("Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`"),
|
|
|
|
)
|
2021-04-05 21:50:50 -07:00
|
|
|
.arg(Arg::with_name(cmd::EVALUATE).long("evaluate").help(
|
2021-04-25 17:25:34 -07:00
|
|
|
"Evaluate and print all variables. If a variable name is given as an argument, only print \
|
|
|
|
that variable's value.",
|
2021-04-05 21:50:50 -07:00
|
|
|
))
|
2021-06-08 01:01:27 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::FORMAT)
|
|
|
|
.long("fmt")
|
|
|
|
.help("Format and overwrite justfile"),
|
|
|
|
)
|
2019-11-19 23:07:44 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::INIT)
|
|
|
|
.long("init")
|
|
|
|
.help("Initialize new justfile in project root"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::LIST)
|
|
|
|
.short("l")
|
|
|
|
.long("list")
|
|
|
|
.help("List available recipes and their arguments"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::SHOW)
|
|
|
|
.short("s")
|
|
|
|
.long("show")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("RECIPE")
|
|
|
|
.help("Show information about <RECIPE>"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::SUMMARY)
|
|
|
|
.long("summary")
|
|
|
|
.help("List names of available recipes"),
|
|
|
|
)
|
2020-03-13 22:19:43 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::VARIABLES)
|
|
|
|
.long("variables")
|
|
|
|
.help("List names of variables"),
|
|
|
|
)
|
2021-08-08 22:37:35 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::DOTENV_FILENAME)
|
|
|
|
.long("dotenv-filename")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Search for environment file named <DOTENV-FILENAME> instead of `.env`")
|
|
|
|
.conflicts_with(arg::DOTENV_PATH),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::DOTENV_PATH)
|
|
|
|
.long("dotenv-path")
|
|
|
|
.help("Load environment file at <DOTENV-PATH> instead of searching for one")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2021-05-09 20:35:35 -07:00
|
|
|
.group(ArgGroup::with_name("SUBCOMMAND").args(cmd::ALL))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::ARGUMENTS)
|
|
|
|
.multiple(true)
|
|
|
|
.help("Overrides and recipe(s) to run, defaulting to the first recipe in the justfile"),
|
|
|
|
);
|
2019-10-07 02:06:45 -07:00
|
|
|
|
|
|
|
if cfg!(feature = "help4help2man") {
|
|
|
|
app.version(env!("CARGO_PKG_VERSION")).about(concat!(
|
|
|
|
"- Please see ",
|
|
|
|
env!("CARGO_PKG_HOMEPAGE"),
|
|
|
|
" for more information."
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
app
|
2021-06-01 16:37:40 -07:00
|
|
|
.version(env!("CARGO_PKG_VERSION"))
|
2019-10-07 02:06:45 -07:00
|
|
|
.author(env!("CARGO_PKG_AUTHORS"))
|
|
|
|
.about(concat!(
|
|
|
|
env!("CARGO_PKG_DESCRIPTION"),
|
|
|
|
" - ",
|
|
|
|
env!("CARGO_PKG_HOMEPAGE")
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 00:07:48 -08:00
|
|
|
fn color_from_matches(matches: &ArgMatches) -> ConfigResult<Color> {
|
|
|
|
let value = matches
|
|
|
|
.value_of(arg::COLOR)
|
|
|
|
.ok_or_else(|| ConfigError::Internal {
|
|
|
|
message: "`--color` had no value".to_string(),
|
|
|
|
})?;
|
|
|
|
|
2019-10-09 00:18:53 -07:00
|
|
|
match value {
|
|
|
|
arg::COLOR_AUTO => Ok(Color::auto()),
|
|
|
|
arg::COLOR_ALWAYS => Ok(Color::always()),
|
|
|
|
arg::COLOR_NEVER => Ok(Color::never()),
|
|
|
|
_ => Err(ConfigError::Internal {
|
2022-12-15 16:53:21 -08:00
|
|
|
message: format!("Invalid argument `{value}` to --color."),
|
2019-10-09 00:18:53 -07:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-10 17:04:34 -07:00
|
|
|
fn command_color_from_matches(matches: &ArgMatches) -> ConfigResult<Option<ansi_term::Color>> {
|
|
|
|
if let Some(value) = matches.value_of(arg::COMMAND_COLOR) {
|
|
|
|
match value {
|
|
|
|
arg::COMMAND_COLOR_BLACK => Ok(Some(ansi_term::Color::Black)),
|
|
|
|
arg::COMMAND_COLOR_BLUE => Ok(Some(ansi_term::Color::Blue)),
|
|
|
|
arg::COMMAND_COLOR_CYAN => Ok(Some(ansi_term::Color::Cyan)),
|
|
|
|
arg::COMMAND_COLOR_GREEN => Ok(Some(ansi_term::Color::Green)),
|
|
|
|
arg::COMMAND_COLOR_PURPLE => Ok(Some(ansi_term::Color::Purple)),
|
|
|
|
arg::COMMAND_COLOR_RED => Ok(Some(ansi_term::Color::Red)),
|
|
|
|
arg::COMMAND_COLOR_YELLOW => Ok(Some(ansi_term::Color::Yellow)),
|
|
|
|
value => Err(ConfigError::Internal {
|
|
|
|
message: format!("Invalid argument `{value}` to --command-color."),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 00:07:48 -08:00
|
|
|
fn dump_format_from_matches(matches: &ArgMatches) -> ConfigResult<DumpFormat> {
|
|
|
|
let value = matches
|
|
|
|
.value_of(arg::DUMP_FORMAT)
|
|
|
|
.ok_or_else(|| ConfigError::Internal {
|
|
|
|
message: "`--dump-format` had no value".to_string(),
|
|
|
|
})?;
|
|
|
|
|
|
|
|
match value {
|
|
|
|
arg::DUMP_FORMAT_JSON => Ok(DumpFormat::Json),
|
|
|
|
arg::DUMP_FORMAT_JUST => Ok(DumpFormat::Just),
|
|
|
|
_ => Err(ConfigError::Internal {
|
2022-12-15 16:53:21 -08:00
|
|
|
message: format!("Invalid argument `{value}` to --dump-format."),
|
2021-11-17 00:07:48 -08:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult<Self> {
|
2022-01-04 09:45:27 -08:00
|
|
|
let invocation_directory = env::current_dir().context(config_error::CurrentDirContext)?;
|
2019-10-09 00:18:53 -07:00
|
|
|
|
2020-10-01 20:00:15 -07:00
|
|
|
let verbosity = if matches.is_present(arg::QUIET) {
|
|
|
|
Verbosity::Quiet
|
|
|
|
} else {
|
|
|
|
Verbosity::from_flag_occurrences(matches.occurrences_of(arg::VERBOSE))
|
|
|
|
};
|
2019-10-07 02:06:45 -07:00
|
|
|
|
2021-11-17 00:07:48 -08:00
|
|
|
let color = Self::color_from_matches(matches)?;
|
2023-10-10 17:04:34 -07:00
|
|
|
let command_color = Self::command_color_from_matches(matches)?;
|
2019-10-07 02:06:45 -07:00
|
|
|
|
2019-10-31 17:39:25 -07:00
|
|
|
let set_count = matches.occurrences_of(arg::SET);
|
2019-10-07 02:06:45 -07:00
|
|
|
let mut overrides = BTreeMap::new();
|
|
|
|
if set_count > 0 {
|
2019-10-31 17:39:25 -07:00
|
|
|
let mut values = matches.values_of(arg::SET).unwrap();
|
2019-10-07 02:06:45 -07:00
|
|
|
for _ in 0..set_count {
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
overrides.insert(
|
|
|
|
values.next().unwrap().to_owned(),
|
|
|
|
values.next().unwrap().to_owned(),
|
|
|
|
);
|
2019-10-07 02:06:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-24 20:25:17 -08:00
|
|
|
let positional = Positional::from_values(matches.values_of(arg::ARGUMENTS));
|
2019-10-07 02:06:45 -07:00
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
for (name, value) in positional.overrides {
|
2021-05-07 00:14:38 -07:00
|
|
|
overrides.insert(name.clone(), value.clone());
|
2019-10-07 02:06:45 -07:00
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
let search_config = {
|
|
|
|
let justfile = matches.value_of(arg::JUSTFILE).map(PathBuf::from);
|
|
|
|
let working_directory = matches.value_of(arg::WORKING_DIRECTORY).map(PathBuf::from);
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
if let Some(search_directory) = positional.search_directory.map(PathBuf::from) {
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
if justfile.is_some() || working_directory.is_some() {
|
|
|
|
return Err(ConfigError::SearchDirConflict);
|
|
|
|
}
|
|
|
|
SearchConfig::FromSearchDirectory { search_directory }
|
|
|
|
} else {
|
|
|
|
match (justfile, working_directory) {
|
|
|
|
(None, None) => SearchConfig::FromInvocationDirectory,
|
|
|
|
(Some(justfile), None) => SearchConfig::WithJustfile { justfile },
|
2021-09-16 06:44:40 -07:00
|
|
|
(Some(justfile), Some(working_directory)) => {
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
SearchConfig::WithJustfileAndWorkingDirectory {
|
|
|
|
justfile,
|
|
|
|
working_directory,
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
(None, Some(_)) => {
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
return Err(ConfigError::internal(
|
|
|
|
"--working-directory set without --justfile",
|
2021-09-16 06:44:40 -07:00
|
|
|
))
|
|
|
|
}
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
}
|
2019-10-07 04:04:39 -07:00
|
|
|
};
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
for subcommand in cmd::ARGLESS {
|
|
|
|
if matches.is_present(subcommand) {
|
|
|
|
match (!overrides.is_empty(), !positional.arguments.is_empty()) {
|
2021-09-16 06:44:40 -07:00
|
|
|
(false, false) => {}
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
(true, false) => {
|
|
|
|
return Err(ConfigError::SubcommandOverrides {
|
2021-04-25 17:02:57 -07:00
|
|
|
subcommand,
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
overrides,
|
|
|
|
});
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
(false, true) => {
|
|
|
|
return Err(ConfigError::SubcommandArguments {
|
2021-04-25 17:02:57 -07:00
|
|
|
arguments: positional.arguments,
|
|
|
|
subcommand,
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
});
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
(true, true) => {
|
|
|
|
return Err(ConfigError::SubcommandOverridesAndArguments {
|
|
|
|
arguments: positional.arguments,
|
2021-04-25 17:02:57 -07:00
|
|
|
subcommand,
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
overrides,
|
|
|
|
});
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 13:53:27 -07:00
|
|
|
let subcommand = if matches.is_present(cmd::CHANGELOG) {
|
|
|
|
Subcommand::Changelog
|
|
|
|
} else if matches.is_present(cmd::CHOOSE) {
|
2020-09-17 19:43:04 -07:00
|
|
|
Subcommand::Choose {
|
|
|
|
chooser: matches.value_of(arg::CHOOSER).map(str::to_owned),
|
|
|
|
overrides,
|
|
|
|
}
|
2021-05-09 20:35:35 -07:00
|
|
|
} else if let Some(values) = matches.values_of_os(cmd::COMMAND) {
|
2021-09-16 07:51:45 -07:00
|
|
|
let mut arguments = values.map(OsStr::to_owned).collect::<Vec<OsString>>();
|
2021-05-09 20:35:35 -07:00
|
|
|
Subcommand::Command {
|
|
|
|
binary: arguments.remove(0),
|
|
|
|
arguments,
|
|
|
|
overrides,
|
|
|
|
}
|
2020-09-17 19:43:04 -07:00
|
|
|
} else if let Some(shell) = matches.value_of(cmd::COMPLETIONS) {
|
2020-01-15 01:20:38 -08:00
|
|
|
Subcommand::Completions {
|
|
|
|
shell: shell.to_owned(),
|
|
|
|
}
|
|
|
|
} else if matches.is_present(cmd::EDIT) {
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
Subcommand::Edit
|
|
|
|
} else if matches.is_present(cmd::SUMMARY) {
|
|
|
|
Subcommand::Summary
|
|
|
|
} else if matches.is_present(cmd::DUMP) {
|
|
|
|
Subcommand::Dump
|
2021-06-08 01:01:27 -07:00
|
|
|
} else if matches.is_present(cmd::FORMAT) {
|
|
|
|
Subcommand::Format
|
2019-11-19 23:07:44 -08:00
|
|
|
} else if matches.is_present(cmd::INIT) {
|
|
|
|
Subcommand::Init
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
} else if matches.is_present(cmd::LIST) {
|
|
|
|
Subcommand::List
|
|
|
|
} else if let Some(name) = matches.value_of(cmd::SHOW) {
|
|
|
|
Subcommand::Show {
|
|
|
|
name: name.to_owned(),
|
|
|
|
}
|
|
|
|
} else if matches.is_present(cmd::EVALUATE) {
|
2021-04-25 17:02:57 -07:00
|
|
|
if positional.arguments.len() > 1 {
|
|
|
|
return Err(ConfigError::SubcommandArguments {
|
|
|
|
subcommand: cmd::EVALUATE,
|
2021-09-16 06:44:40 -07:00
|
|
|
arguments: positional
|
2021-04-25 17:02:57 -07:00
|
|
|
.arguments
|
|
|
|
.into_iter()
|
|
|
|
.skip(1)
|
|
|
|
.collect::<Vec<String>>(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-05 21:50:50 -07:00
|
|
|
Subcommand::Evaluate {
|
2021-04-25 17:02:57 -07:00
|
|
|
variable: positional.arguments.into_iter().next(),
|
2021-04-05 21:50:50 -07:00
|
|
|
overrides,
|
2019-11-19 23:07:44 -08:00
|
|
|
}
|
2020-03-13 22:19:43 -07:00
|
|
|
} else if matches.is_present(cmd::VARIABLES) {
|
|
|
|
Subcommand::Variables
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
} else {
|
|
|
|
Subcommand::Run {
|
|
|
|
arguments: positional.arguments,
|
|
|
|
overrides,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-18 11:02:15 -08:00
|
|
|
let shell_args = if matches.occurrences_of(arg::SHELL_ARG) > 0
|
|
|
|
|| matches.occurrences_of(arg::CLEAR_SHELL_ARGS) > 0
|
|
|
|
{
|
|
|
|
Some(
|
|
|
|
matches
|
|
|
|
.values_of(arg::SHELL_ARG)
|
|
|
|
.map_or(Vec::new(), |shell_args| {
|
|
|
|
shell_args.map(str::to_owned).collect()
|
|
|
|
}),
|
|
|
|
)
|
2019-11-22 11:33:56 -08:00
|
|
|
} else {
|
2022-01-18 11:02:15 -08:00
|
|
|
None
|
2019-11-22 11:33:56 -08:00
|
|
|
};
|
|
|
|
|
2023-10-08 20:47:20 -07:00
|
|
|
let unstable = matches.is_present(arg::UNSTABLE)
|
2023-10-16 20:07:09 -07:00
|
|
|
|| env::var_os("JUST_UNSTABLE")
|
2023-10-08 20:47:20 -07:00
|
|
|
.map(|val| !(val == "false" || val == "0" || val.is_empty()))
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
Ok(Self {
|
2021-10-31 21:27:59 -07:00
|
|
|
check: matches.is_present(arg::CHECK),
|
2019-10-31 17:39:25 -07:00
|
|
|
dry_run: matches.is_present(arg::DRY_RUN),
|
2021-11-17 00:07:48 -08:00
|
|
|
dump_format: Self::dump_format_from_matches(matches)?,
|
2019-11-07 11:50:11 -08:00
|
|
|
highlight: !matches.is_present(arg::NO_HIGHLIGHT),
|
2022-01-18 11:02:15 -08:00
|
|
|
shell: matches.value_of(arg::SHELL).map(str::to_owned),
|
2020-05-23 20:41:12 -07:00
|
|
|
load_dotenv: !matches.is_present(arg::NO_DOTENV),
|
2021-05-09 20:35:35 -07:00
|
|
|
shell_command: matches.is_present(arg::SHELL_COMMAND),
|
2020-08-21 15:13:54 -07:00
|
|
|
unsorted: matches.is_present(arg::UNSORTED),
|
2023-10-08 20:47:20 -07:00
|
|
|
unstable,
|
2021-02-09 01:00:04 -08:00
|
|
|
list_heading: matches
|
|
|
|
.value_of(arg::LIST_HEADING)
|
|
|
|
.unwrap_or("Available recipes:\n")
|
|
|
|
.to_owned(),
|
|
|
|
list_prefix: matches
|
|
|
|
.value_of(arg::LIST_PREFIX)
|
|
|
|
.unwrap_or(" ")
|
|
|
|
.to_owned(),
|
2019-11-22 11:33:56 -08:00
|
|
|
color,
|
2023-10-10 17:04:34 -07:00
|
|
|
command_color,
|
2019-10-09 00:18:53 -07:00
|
|
|
invocation_directory,
|
2019-11-22 11:33:56 -08:00
|
|
|
search_config,
|
|
|
|
shell_args,
|
2019-10-07 04:04:39 -07:00
|
|
|
subcommand,
|
2021-08-08 22:37:35 -07:00
|
|
|
dotenv_filename: matches.value_of(arg::DOTENV_FILENAME).map(str::to_owned),
|
|
|
|
dotenv_path: matches.value_of(arg::DOTENV_PATH).map(PathBuf::from),
|
2019-10-07 02:06:45 -07:00
|
|
|
verbosity,
|
2019-10-09 00:18:53 -07:00
|
|
|
})
|
2019-10-07 02:06:45 -07:00
|
|
|
}
|
|
|
|
|
2021-07-26 17:19:52 -07:00
|
|
|
pub(crate) fn require_unstable(&self, message: &str) -> Result<(), Error<'static>> {
|
2021-07-26 01:26:06 -07:00
|
|
|
if self.unstable {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(Error::Unstable {
|
|
|
|
message: message.to_owned(),
|
|
|
|
})
|
2021-06-12 15:34:41 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
}
|
2021-06-12 15:34:41 -07:00
|
|
|
|
2022-09-11 02:25:38 -07:00
|
|
|
pub(crate) fn run(self, loader: &Loader) -> Result<(), Error> {
|
2022-03-30 22:13:59 -07:00
|
|
|
if let Err(error) = InterruptHandler::install(self.verbosity) {
|
2023-10-16 20:07:09 -07:00
|
|
|
warn!("Failed to set CTRL-C handler: {error}");
|
2022-03-30 22:13:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
self.subcommand.execute(&self, loader)
|
2020-03-13 22:19:43 -07:00
|
|
|
}
|
2019-10-07 02:06:45 -07:00
|
|
|
}
|
2019-10-31 17:39:25 -07:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
macro_rules! test {
|
|
|
|
{
|
|
|
|
name: $name:ident,
|
|
|
|
args: [$($arg:expr),*],
|
|
|
|
$(color: $color:expr,)?
|
|
|
|
$(dry_run: $dry_run:expr,)?
|
2021-11-17 00:07:48 -08:00
|
|
|
$(dump_format: $dump_format:expr,)?
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
$(highlight: $highlight:expr,)?
|
|
|
|
$(search_config: $search_config:expr,)?
|
|
|
|
$(shell: $shell:expr,)?
|
2019-11-22 11:33:56 -08:00
|
|
|
$(shell_args: $shell_args:expr,)?
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
$(subcommand: $subcommand:expr,)?
|
2020-08-21 15:13:54 -07:00
|
|
|
$(unsorted: $unsorted:expr,)?
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
$(verbosity: $verbosity:expr,)?
|
|
|
|
} => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
let arguments = &[
|
|
|
|
"just",
|
|
|
|
$($arg,)*
|
|
|
|
];
|
|
|
|
|
|
|
|
let want = Config {
|
|
|
|
$(color: $color,)?
|
|
|
|
$(dry_run: $dry_run,)?
|
2021-11-17 00:07:48 -08:00
|
|
|
$(dump_format: $dump_format,)?
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
$(highlight: $highlight,)?
|
|
|
|
$(search_config: $search_config,)?
|
2022-01-18 11:02:15 -08:00
|
|
|
$(shell: $shell,)?
|
2019-11-22 11:33:56 -08:00
|
|
|
$(shell_args: $shell_args,)?
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
$(subcommand: $subcommand,)?
|
2020-08-21 15:13:54 -07:00
|
|
|
$(unsorted: $unsorted,)?
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
$(verbosity: $verbosity,)?
|
|
|
|
..testing::config(&[])
|
|
|
|
};
|
|
|
|
|
|
|
|
test(arguments, want);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test(arguments: &[&str], want: Config) {
|
|
|
|
let app = Config::app();
|
|
|
|
let matches = app
|
|
|
|
.get_matches_from_safe(arguments)
|
2022-05-28 19:07:53 -07:00
|
|
|
.expect("argument parsing failed");
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
let have = Config::from_matches(&matches).expect("config parsing failed");
|
|
|
|
assert_eq!(have, want);
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! error {
|
|
|
|
{
|
|
|
|
name: $name:ident,
|
|
|
|
args: [$($arg:expr),*],
|
|
|
|
} => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
let arguments = &[
|
|
|
|
"just",
|
|
|
|
$($arg,)*
|
|
|
|
];
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
let app = Config::app();
|
|
|
|
|
|
|
|
app.get_matches_from_safe(arguments).expect_err("Expected clap error");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
{
|
|
|
|
name: $name:ident,
|
|
|
|
args: [$($arg:expr),*],
|
|
|
|
error: $error:pat,
|
|
|
|
$(check: $check:block,)?
|
|
|
|
} => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
let arguments = &[
|
|
|
|
"just",
|
|
|
|
$($arg,)*
|
|
|
|
];
|
|
|
|
|
|
|
|
let app = Config::app();
|
|
|
|
|
2022-05-28 19:07:53 -07:00
|
|
|
let matches = app.get_matches_from_safe(arguments).expect("Matching fails");
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
|
|
|
|
match Config::from_matches(&matches).expect_err("config parsing succeeded") {
|
|
|
|
$error => { $($check)? }
|
2023-10-16 20:07:09 -07:00
|
|
|
other => panic!("Unexpected config error: {other}"),
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
}
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
macro_rules! map {
|
|
|
|
{} => {
|
|
|
|
BTreeMap::new()
|
|
|
|
};
|
|
|
|
{
|
|
|
|
$($key:literal : $value:literal),* $(,)?
|
|
|
|
} => {
|
|
|
|
{
|
|
|
|
let mut map: BTreeMap<String, String> = BTreeMap::new();
|
|
|
|
$(
|
|
|
|
map.insert($key.to_owned(), $value.to_owned());
|
|
|
|
)*
|
|
|
|
map
|
|
|
|
}
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: default_config,
|
|
|
|
args: [],
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: color_default,
|
|
|
|
args: [],
|
|
|
|
color: Color::auto(),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: color_never,
|
|
|
|
args: ["--color", "never"],
|
|
|
|
color: Color::never(),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: color_always,
|
|
|
|
args: ["--color", "always"],
|
|
|
|
color: Color::always(),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: color_auto,
|
|
|
|
args: ["--color", "auto"],
|
|
|
|
color: Color::auto(),
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: color_bad_value,
|
|
|
|
args: ["--color", "foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: dry_run_default,
|
|
|
|
args: [],
|
|
|
|
dry_run: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
2023-01-23 23:48:30 -08:00
|
|
|
name: dry_run_long,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
args: ["--dry-run"],
|
|
|
|
dry_run: true,
|
|
|
|
}
|
|
|
|
|
2023-01-23 23:48:30 -08:00
|
|
|
test! {
|
|
|
|
name: dry_run_short,
|
|
|
|
args: ["-n"],
|
|
|
|
dry_run: true,
|
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
error! {
|
|
|
|
name: dry_run_quiet,
|
|
|
|
args: ["--dry-run", "--quiet"],
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: highlight_default,
|
|
|
|
args: [],
|
|
|
|
highlight: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: highlight_yes,
|
|
|
|
args: ["--highlight"],
|
|
|
|
highlight: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: highlight_no,
|
|
|
|
args: ["--no-highlight"],
|
|
|
|
highlight: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: highlight_no_yes,
|
|
|
|
args: ["--no-highlight", "--highlight"],
|
|
|
|
highlight: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: highlight_no_yes_no,
|
|
|
|
args: ["--no-highlight", "--highlight", "--no-highlight"],
|
|
|
|
highlight: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: highlight_yes_no,
|
|
|
|
args: ["--highlight", "--no-highlight"],
|
|
|
|
highlight: false,
|
|
|
|
}
|
|
|
|
|
2020-08-21 15:13:54 -07:00
|
|
|
test! {
|
|
|
|
name: unsorted_default,
|
|
|
|
args: [],
|
|
|
|
unsorted: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unsorted_long,
|
|
|
|
args: ["--unsorted"],
|
|
|
|
unsorted: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unsorted_short,
|
|
|
|
args: ["-u"],
|
|
|
|
unsorted: true,
|
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
test! {
|
|
|
|
name: quiet_default,
|
|
|
|
args: [],
|
2020-10-01 20:00:15 -07:00
|
|
|
verbosity: Verbosity::Taciturn,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: quiet_long,
|
|
|
|
args: ["--quiet"],
|
2020-10-01 20:00:15 -07:00
|
|
|
verbosity: Verbosity::Quiet,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: quiet_short,
|
|
|
|
args: ["-q"],
|
2020-10-01 20:00:15 -07:00
|
|
|
verbosity: Verbosity::Quiet,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
2021-08-08 22:37:35 -07:00
|
|
|
error! {
|
|
|
|
name: dotenv_both_filename_and_path,
|
|
|
|
args: ["--dotenv-filename", "foo", "--dotenv-path", "bar"],
|
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
test! {
|
|
|
|
name: set_default,
|
|
|
|
args: [],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!(),
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: set_one,
|
|
|
|
args: ["--set", "foo", "bar"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!{"foo": "bar"},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: set_empty,
|
|
|
|
args: ["--set", "foo", ""],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!{"foo": ""},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: set_two,
|
|
|
|
args: ["--set", "foo", "bar", "--set", "bar", "baz"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!{"foo": "bar", "bar": "baz"},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: set_override,
|
|
|
|
args: ["--set", "foo", "bar", "--set", "foo", "baz"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!{"foo": "baz"},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: set_bad,
|
|
|
|
args: ["--set", "foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_default,
|
|
|
|
args: [],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell: None,
|
|
|
|
shell_args: None,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_set,
|
|
|
|
args: ["--shell", "tclsh"],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell: Some("tclsh".to_owned()),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set,
|
|
|
|
args: ["--shell-arg", "hello"],
|
|
|
|
shell: None,
|
|
|
|
shell_args: Some(vec!["hello".into()]),
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: verbosity_default,
|
|
|
|
args: [],
|
|
|
|
verbosity: Verbosity::Taciturn,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: verbosity_long,
|
|
|
|
args: ["--verbose"],
|
|
|
|
verbosity: Verbosity::Loquacious,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: verbosity_loquacious,
|
|
|
|
args: ["-v"],
|
|
|
|
verbosity: Verbosity::Loquacious,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: verbosity_grandiloquent,
|
|
|
|
args: ["-v", "-v"],
|
|
|
|
verbosity: Verbosity::Grandiloquent,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: verbosity_great_grandiloquent,
|
|
|
|
args: ["-v", "-v", "-v"],
|
|
|
|
verbosity: Verbosity::Grandiloquent,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: subcommand_default,
|
|
|
|
args: [],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!{},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
2021-07-31 13:53:27 -07:00
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_changelog,
|
|
|
|
args: ["--list", "--changelog"],
|
|
|
|
}
|
|
|
|
|
2020-09-17 19:43:04 -07:00
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_summary,
|
|
|
|
args: ["--list", "--summary"],
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_dump,
|
|
|
|
args: ["--list", "--dump"],
|
|
|
|
}
|
|
|
|
|
2021-06-08 01:01:27 -07:00
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_fmt,
|
|
|
|
args: ["--list", "--fmt"],
|
|
|
|
}
|
|
|
|
|
2020-09-17 19:43:04 -07:00
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_init,
|
|
|
|
args: ["--list", "--init"],
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_evaluate,
|
|
|
|
args: ["--list", "--evaluate"],
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_show,
|
|
|
|
args: ["--list", "--show"],
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_completions,
|
|
|
|
args: ["--list", "--completions"],
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_variables,
|
|
|
|
args: ["--list", "--variables"],
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_conflict_choose,
|
|
|
|
args: ["--list", "--choose"],
|
|
|
|
}
|
|
|
|
|
2020-01-15 01:20:38 -08:00
|
|
|
test! {
|
|
|
|
name: subcommand_completions,
|
|
|
|
args: ["--completions", "bash"],
|
|
|
|
subcommand: Subcommand::Completions{shell: "bash".to_owned()},
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: subcommand_completions_uppercase,
|
|
|
|
args: ["--completions", "BASH"],
|
|
|
|
subcommand: Subcommand::Completions{shell: "BASH".to_owned()},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_completions_invalid,
|
|
|
|
args: ["--completions", "monstersh"],
|
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
test! {
|
|
|
|
name: subcommand_dump,
|
|
|
|
args: ["--dump"],
|
|
|
|
subcommand: Subcommand::Dump,
|
|
|
|
}
|
|
|
|
|
2021-11-17 00:07:48 -08:00
|
|
|
test! {
|
|
|
|
name: dump_format,
|
|
|
|
args: ["--dump-format", "json"],
|
|
|
|
dump_format: DumpFormat::Json,
|
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
test! {
|
|
|
|
name: subcommand_edit,
|
|
|
|
args: ["--edit"],
|
|
|
|
subcommand: Subcommand::Edit,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: subcommand_evaluate,
|
|
|
|
args: ["--evaluate"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Evaluate {
|
|
|
|
overrides: map!{},
|
2021-04-25 17:02:57 -07:00
|
|
|
variable: None,
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
2019-11-19 23:07:44 -08:00
|
|
|
test! {
|
|
|
|
name: subcommand_evaluate_overrides,
|
|
|
|
args: ["--evaluate", "x=y"],
|
|
|
|
subcommand: Subcommand::Evaluate {
|
|
|
|
overrides: map!{"x": "y"},
|
2021-04-25 17:02:57 -07:00
|
|
|
variable: None,
|
2021-04-05 21:50:50 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: subcommand_evaluate_overrides_with_argument,
|
|
|
|
args: ["--evaluate", "x=y", "foo"],
|
|
|
|
subcommand: Subcommand::Evaluate {
|
|
|
|
overrides: map!{"x": "y"},
|
2021-04-25 17:02:57 -07:00
|
|
|
variable: Some("foo".to_owned()),
|
2019-11-19 23:07:44 -08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
test! {
|
|
|
|
name: subcommand_list_long,
|
|
|
|
args: ["--list"],
|
|
|
|
subcommand: Subcommand::List,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: subcommand_list_short,
|
|
|
|
args: ["-l"],
|
|
|
|
subcommand: Subcommand::List,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: subcommand_show_long,
|
|
|
|
args: ["--show", "build"],
|
|
|
|
subcommand: Subcommand::Show { name: String::from("build") },
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: subcommand_show_short,
|
|
|
|
args: ["-s", "build"],
|
|
|
|
subcommand: Subcommand::Show { name: String::from("build") },
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_show_no_arg,
|
|
|
|
args: ["--show"],
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: subcommand_summary,
|
|
|
|
args: ["--summary"],
|
|
|
|
subcommand: Subcommand::Summary,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: arguments,
|
|
|
|
args: ["foo", "bar"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: vec![String::from("foo"), String::from("bar")],
|
|
|
|
overrides: map!{},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: arguments_leading_equals,
|
|
|
|
args: ["=foo"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
2021-05-07 00:14:38 -07:00
|
|
|
arguments: vec!["=foo".to_owned()],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
overrides: map!{},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: overrides,
|
|
|
|
args: ["foo=bar", "bar=baz"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!{"foo": "bar", "bar": "baz"},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: overrides_empty,
|
|
|
|
args: ["foo=", "bar="],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!{"foo": "", "bar": ""},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: overrides_override_sets,
|
|
|
|
args: ["--set", "foo", "0", "--set", "bar", "1", "foo=bar", "bar=baz"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run {
|
|
|
|
arguments: Vec::new(),
|
|
|
|
overrides: map!{"foo": "bar", "bar": "baz"},
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
2019-11-22 11:33:56 -08:00
|
|
|
test! {
|
|
|
|
name: shell_args_default,
|
|
|
|
args: [],
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_hyphen,
|
|
|
|
args: ["--shell-arg", "--foo"],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell_args: Some(vec!["--foo".to_owned()]),
|
2019-11-22 11:33:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_word,
|
|
|
|
args: ["--shell-arg", "foo"],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell_args: Some(vec!["foo".to_owned()]),
|
2019-11-22 11:33:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_multiple,
|
|
|
|
args: ["--shell-arg", "foo", "--shell-arg", "bar"],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell_args: Some(vec!["foo".to_owned(), "bar".to_owned()]),
|
|
|
|
|
2019-11-22 11:33:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_clear,
|
|
|
|
args: ["--clear-shell-args"],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell_args: Some(vec![]),
|
|
|
|
|
2019-11-22 11:33:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_clear_and_set,
|
|
|
|
args: ["--clear-shell-args", "--shell-arg", "bar"],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell_args: Some(vec!["bar".to_owned()]),
|
|
|
|
|
2019-11-22 11:33:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_and_clear,
|
|
|
|
args: ["--shell-arg", "bar", "--clear-shell-args"],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell_args: Some(vec![]),
|
|
|
|
|
2019-11-22 11:33:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_multiple_and_clear,
|
|
|
|
args: ["--shell-arg", "bar", "--shell-arg", "baz", "--clear-shell-args"],
|
2022-01-18 11:02:15 -08:00
|
|
|
shell_args: Some(vec![]),
|
|
|
|
|
2019-11-22 11:33:56 -08:00
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
test! {
|
|
|
|
name: search_config_default,
|
|
|
|
args: [],
|
|
|
|
search_config: SearchConfig::FromInvocationDirectory,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: search_config_from_working_directory_and_justfile,
|
|
|
|
args: ["--working-directory", "foo", "--justfile", "bar"],
|
|
|
|
search_config: SearchConfig::WithJustfileAndWorkingDirectory {
|
|
|
|
justfile: PathBuf::from("bar"),
|
|
|
|
working_directory: PathBuf::from("foo"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: search_config_justfile_long,
|
|
|
|
args: ["--justfile", "foo"],
|
|
|
|
search_config: SearchConfig::WithJustfile {
|
|
|
|
justfile: PathBuf::from("foo"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: search_config_justfile_short,
|
|
|
|
args: ["-f", "foo"],
|
|
|
|
search_config: SearchConfig::WithJustfile {
|
|
|
|
justfile: PathBuf::from("foo"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: search_directory_parent,
|
|
|
|
args: ["../"],
|
|
|
|
search_config: SearchConfig::FromSearchDirectory {
|
|
|
|
search_directory: PathBuf::from(".."),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: search_directory_parent_with_recipe,
|
|
|
|
args: ["../build"],
|
|
|
|
search_config: SearchConfig::FromSearchDirectory {
|
|
|
|
search_directory: PathBuf::from(".."),
|
|
|
|
},
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run { arguments: vec!["build".to_owned()], overrides: BTreeMap::new() },
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: search_directory_child,
|
|
|
|
args: ["foo/"],
|
|
|
|
search_config: SearchConfig::FromSearchDirectory {
|
|
|
|
search_directory: PathBuf::from("foo"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: search_directory_deep,
|
|
|
|
args: ["foo/bar/"],
|
|
|
|
search_config: SearchConfig::FromSearchDirectory {
|
|
|
|
search_directory: PathBuf::from("foo/bar"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: search_directory_child_with_recipe,
|
|
|
|
args: ["foo/build"],
|
|
|
|
search_config: SearchConfig::FromSearchDirectory {
|
|
|
|
search_directory: PathBuf::from("foo"),
|
|
|
|
},
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
subcommand: Subcommand::Run { arguments: vec!["build".to_owned()], overrides: BTreeMap::new() },
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: search_directory_conflict_justfile,
|
|
|
|
args: ["--justfile", "bar", "foo/build"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
error: ConfigError::SearchDirConflict,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: search_directory_conflict_working_directory,
|
|
|
|
args: ["--justfile", "bar", "--working-directory", "baz", "foo/build"],
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
error: ConfigError::SearchDirConflict,
|
|
|
|
}
|
|
|
|
|
2020-01-15 01:20:38 -08:00
|
|
|
error! {
|
|
|
|
name: completions_arguments,
|
|
|
|
args: ["--completions", "zsh", "foo"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::COMPLETIONS);
|
2020-01-15 01:20:38 -08:00
|
|
|
assert_eq!(arguments, &["foo"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-07-31 13:53:27 -07:00
|
|
|
error! {
|
|
|
|
name: changelog_arguments,
|
|
|
|
args: ["--changelog", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, cmd::CHANGELOG);
|
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
error! {
|
|
|
|
name: list_arguments,
|
|
|
|
args: ["--list", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::LIST);
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: dump_arguments,
|
|
|
|
args: ["--dump", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::DUMP);
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: edit_arguments,
|
|
|
|
args: ["--edit", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::EDIT);
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-06-08 01:01:27 -07:00
|
|
|
error! {
|
|
|
|
name: fmt_arguments,
|
|
|
|
args: ["--fmt", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, cmd::FORMAT);
|
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:07:44 -08:00
|
|
|
error! {
|
|
|
|
name: init_arguments,
|
|
|
|
args: ["--init", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::INIT);
|
2019-11-19 23:07:44 -08:00
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
error! {
|
|
|
|
name: show_arguments,
|
|
|
|
args: ["--show", "foo", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::SHOW);
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: summary_arguments,
|
|
|
|
args: ["--summary", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::SUMMARY);
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_overrides_and_arguments,
|
|
|
|
args: ["--summary", "bar=baz", "bar"],
|
|
|
|
error: ConfigError::SubcommandOverridesAndArguments { subcommand, arguments, overrides },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::SUMMARY);
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
assert_eq!(overrides, map!{"bar": "baz"});
|
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: summary_overrides,
|
|
|
|
args: ["--summary", "bar=baz"],
|
|
|
|
error: ConfigError::SubcommandOverrides { subcommand, overrides },
|
|
|
|
check: {
|
2021-04-25 17:02:57 -07:00
|
|
|
assert_eq!(subcommand, cmd::SUMMARY);
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
assert_eq!(overrides, map!{"bar": "baz"});
|
|
|
|
},
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
}
|
2019-10-31 17:39:25 -07:00
|
|
|
}
|