2019-10-07 02:06:45 -07:00
|
|
|
use crate::common::*;
|
|
|
|
|
2020-01-15 01:20:38 -08:00
|
|
|
use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, ArgSettings};
|
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
|
|
|
use unicode_width::UnicodeWidthStr;
|
2019-10-07 02:06:45 -07:00
|
|
|
|
|
|
|
pub(crate) const DEFAULT_SHELL: &str = "sh";
|
2019-11-22 11:33:56 -08:00
|
|
|
pub(crate) const DEFAULT_SHELL_ARG: &str = "-cu";
|
2019-11-19 23:07:44 -08:00
|
|
|
pub(crate) const INIT_JUSTFILE: &str = "default:\n\techo 'Hello, world!'\n";
|
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
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub(crate) struct Config {
|
2020-02-10 20:07:06 -08:00
|
|
|
pub(crate) color: Color,
|
|
|
|
pub(crate) dry_run: bool,
|
|
|
|
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,
|
2020-05-23 20:41:12 -07:00
|
|
|
pub(crate) load_dotenv: bool,
|
2020-02-10 20:07:06 -08:00
|
|
|
pub(crate) quiet: bool,
|
|
|
|
pub(crate) search_config: SearchConfig,
|
|
|
|
pub(crate) shell: String,
|
|
|
|
pub(crate) shell_args: Vec<String>,
|
|
|
|
pub(crate) shell_present: bool,
|
|
|
|
pub(crate) subcommand: Subcommand,
|
|
|
|
pub(crate) verbosity: Verbosity,
|
2019-10-07 02:06:45 -07:00
|
|
|
}
|
|
|
|
|
2019-10-31 17:39:25 -07:00
|
|
|
mod cmd {
|
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";
|
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] = &[
|
|
|
|
COMPLETIONS,
|
|
|
|
DUMP,
|
|
|
|
EDIT,
|
|
|
|
INIT,
|
|
|
|
EVALUATE,
|
|
|
|
LIST,
|
|
|
|
SHOW,
|
|
|
|
SUMMARY,
|
|
|
|
VARIABLES,
|
|
|
|
];
|
|
|
|
|
|
|
|
pub(crate) const ARGLESS: &[&str] = &[
|
|
|
|
COMPLETIONS,
|
|
|
|
DUMP,
|
|
|
|
EDIT,
|
|
|
|
INIT,
|
|
|
|
LIST,
|
|
|
|
SHOW,
|
|
|
|
SUMMARY,
|
|
|
|
VARIABLES,
|
|
|
|
];
|
2019-10-31 17:39:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mod arg {
|
|
|
|
pub(crate) const ARGUMENTS: &str = "ARGUMENTS";
|
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";
|
|
|
|
pub(crate) const DRY_RUN: &str = "DRY-RUN";
|
|
|
|
pub(crate) const HIGHLIGHT: &str = "HIGHLIGHT";
|
|
|
|
pub(crate) const JUSTFILE: &str = "JUSTFILE";
|
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";
|
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];
|
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)
|
|
|
|
.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"),
|
|
|
|
)
|
|
|
|
.arg(
|
2019-10-31 17:39:25 -07:00
|
|
|
Arg::with_name(arg::DRY_RUN)
|
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
|
|
|
)
|
|
|
|
.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),
|
|
|
|
)
|
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)
|
|
|
|
.help("Use <JUSTFILE> as justfile."),
|
|
|
|
)
|
|
|
|
.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)
|
|
|
|
.default_value(DEFAULT_SHELL)
|
|
|
|
.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)
|
|
|
|
.default_value(DEFAULT_SHELL_ARG)
|
|
|
|
.allow_hyphen_values(true)
|
|
|
|
.overrides_with(arg::CLEAR_SHELL_ARGS)
|
|
|
|
.help("Invoke shell with <SHELL-ARG> as an argument"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(arg::CLEAR_SHELL_ARGS)
|
|
|
|
.long("clear-shell-args")
|
|
|
|
.overrides_with(arg::SHELL_ARG)
|
|
|
|
.help("Clear shell arguments"),
|
|
|
|
)
|
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
|
|
|
)
|
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(
|
|
|
|
Arg::with_name(arg::ARGUMENTS)
|
|
|
|
.multiple(true)
|
|
|
|
.help("Overrides and recipe(s) to run, defaulting to the first recipe in the justfile"),
|
|
|
|
)
|
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")
|
|
|
|
.help("Print entire justfile"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::EDIT)
|
|
|
|
.short("e")
|
|
|
|
.long("edit")
|
|
|
|
.help("Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(cmd::EVALUATE)
|
|
|
|
.long("evaluate")
|
|
|
|
.help("Print evaluated variables"),
|
|
|
|
)
|
|
|
|
.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"),
|
|
|
|
)
|
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
|
|
|
.group(ArgGroup::with_name("SUBCOMMAND").args(cmd::ALL));
|
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
|
|
|
|
.version(concat!("v", env!("CARGO_PKG_VERSION")))
|
|
|
|
.author(env!("CARGO_PKG_AUTHORS"))
|
|
|
|
.about(concat!(
|
|
|
|
env!("CARGO_PKG_DESCRIPTION"),
|
|
|
|
" - ",
|
|
|
|
env!("CARGO_PKG_HOMEPAGE")
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:18:53 -07:00
|
|
|
fn color_from_value(value: &str) -> ConfigResult<Color> {
|
|
|
|
match value {
|
|
|
|
arg::COLOR_AUTO => Ok(Color::auto()),
|
|
|
|
arg::COLOR_ALWAYS => Ok(Color::always()),
|
|
|
|
arg::COLOR_NEVER => Ok(Color::never()),
|
|
|
|
_ => Err(ConfigError::Internal {
|
|
|
|
message: format!("Invalid argument `{}` to --color.", value),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult<Self> {
|
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 invocation_directory = env::current_dir().context(config_error::CurrentDir)?;
|
2019-10-09 00:18:53 -07:00
|
|
|
|
2019-10-31 17:39:25 -07:00
|
|
|
let verbosity = Verbosity::from_flag_occurrences(matches.occurrences_of(arg::VERBOSE));
|
2019-10-07 02:06:45 -07:00
|
|
|
|
2019-10-09 00:18:53 -07:00
|
|
|
let color = Self::color_from_value(
|
|
|
|
matches
|
|
|
|
.value_of(arg::COLOR)
|
|
|
|
.expect("`--color` had no value"),
|
|
|
|
)?;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 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 {
|
|
|
|
overrides.insert(name.to_owned(), value.to_owned());
|
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 },
|
2020-02-10 20:07:06 -08: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,
|
2020-02-10 20:07:06 -08: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",
|
2020-02-10 20:07:06 -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-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()) {
|
2020-02-10 20:07:06 -08: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 {
|
|
|
|
subcommand: format!("--{}", subcommand.to_lowercase()),
|
|
|
|
overrides,
|
|
|
|
});
|
2020-02-10 20:07:06 -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
|
|
|
(false, true) => {
|
|
|
|
return Err(ConfigError::SubcommandArguments {
|
|
|
|
subcommand: format!("--{}", subcommand.to_lowercase()),
|
2020-02-10 20:07:06 -08:00
|
|
|
arguments: positional.arguments,
|
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-02-10 20:07:06 -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
|
|
|
(true, true) => {
|
|
|
|
return Err(ConfigError::SubcommandOverridesAndArguments {
|
|
|
|
subcommand: format!("--{}", subcommand.to_lowercase()),
|
|
|
|
arguments: positional.arguments,
|
|
|
|
overrides,
|
|
|
|
});
|
2020-02-10 20:07:06 -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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 01:20:38 -08:00
|
|
|
let subcommand = if let Some(shell) = matches.value_of(cmd::COMPLETIONS) {
|
|
|
|
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
|
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) {
|
2019-11-19 23:07:44 -08:00
|
|
|
if !positional.arguments.is_empty() {
|
|
|
|
return Err(ConfigError::SubcommandArguments {
|
|
|
|
subcommand: format!("--{}", cmd::EVALUATE.to_lowercase()),
|
2020-02-10 20:07:06 -08:00
|
|
|
arguments: positional.arguments,
|
2019-11-19 23:07:44 -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
|
|
|
Subcommand::Evaluate { overrides }
|
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,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-22 11:33:56 -08:00
|
|
|
let shell_args = if matches.is_present(arg::CLEAR_SHELL_ARGS) {
|
|
|
|
Vec::new()
|
|
|
|
} else {
|
|
|
|
matches
|
|
|
|
.values_of(arg::SHELL_ARG)
|
|
|
|
.unwrap()
|
|
|
|
.map(str::to_owned)
|
|
|
|
.collect()
|
|
|
|
};
|
|
|
|
|
|
|
|
let shell_present = matches.occurrences_of(arg::CLEAR_SHELL_ARGS) > 0
|
|
|
|
|| matches.occurrences_of(arg::SHELL) > 0
|
|
|
|
|| matches.occurrences_of(arg::SHELL_ARG) > 0;
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
Ok(Self {
|
2019-10-31 17:39:25 -07:00
|
|
|
dry_run: matches.is_present(arg::DRY_RUN),
|
2019-11-07 11:50:11 -08:00
|
|
|
highlight: !matches.is_present(arg::NO_HIGHLIGHT),
|
2019-10-31 17:39:25 -07:00
|
|
|
quiet: matches.is_present(arg::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
|
|
|
shell: matches.value_of(arg::SHELL).unwrap().to_owned(),
|
2020-05-23 20:41:12 -07:00
|
|
|
load_dotenv: !matches.is_present(arg::NO_DOTENV),
|
2019-11-22 11:33:56 -08:00
|
|
|
color,
|
2019-10-09 00:18:53 -07:00
|
|
|
invocation_directory,
|
2019-11-22 11:33:56 -08:00
|
|
|
search_config,
|
|
|
|
shell_args,
|
|
|
|
shell_present,
|
2019-10-07 04:04:39 -07:00
|
|
|
subcommand,
|
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
|
|
|
}
|
|
|
|
|
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) fn run_subcommand(self) -> Result<(), i32> {
|
|
|
|
use Subcommand::*;
|
|
|
|
|
2019-11-19 23:07:44 -08:00
|
|
|
if self.subcommand == Init {
|
|
|
|
return self.init();
|
|
|
|
}
|
|
|
|
|
2020-02-20 06:07:25 -08:00
|
|
|
if let Completions { shell } = self.subcommand {
|
2020-03-16 17:20:14 -07:00
|
|
|
return Subcommand::completions(&shell);
|
2020-02-20 06:07:25 -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
|
|
|
let search =
|
2019-11-19 23:07:44 -08:00
|
|
|
Search::find(&self.search_config, &self.invocation_directory).eprint(self.color)?;
|
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 self.subcommand == Edit {
|
2020-01-15 02:16:13 -08:00
|
|
|
return Self::edit(&search);
|
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 src = fs::read_to_string(&search.justfile)
|
|
|
|
.map_err(|io_error| LoadError {
|
|
|
|
io_error,
|
|
|
|
path: &search.justfile,
|
|
|
|
})
|
|
|
|
.eprint(self.color)?;
|
|
|
|
|
|
|
|
let justfile = Compiler::compile(&src).eprint(self.color)?;
|
|
|
|
|
|
|
|
for warning in &justfile.warnings {
|
|
|
|
if self.color.stderr().active() {
|
|
|
|
eprintln!("{:#}", warning);
|
|
|
|
} else {
|
|
|
|
eprintln!("{}", warning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 &self.subcommand {
|
2020-01-15 02:16:13 -08:00
|
|
|
Dump => Self::dump(justfile),
|
2019-12-25 06:12:06 -08:00
|
|
|
Evaluate { overrides } => self.run(justfile, &search, overrides, &Vec::new()),
|
2020-03-13 22:19:43 -07:00
|
|
|
List => self.list(justfile),
|
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
|
|
|
Run {
|
|
|
|
arguments,
|
|
|
|
overrides,
|
2019-12-25 06:12:06 -08:00
|
|
|
} => self.run(justfile, &search, overrides, arguments),
|
2020-01-15 02:16:13 -08:00
|
|
|
Show { ref name } => Self::show(&name, justfile),
|
|
|
|
Summary => Self::summary(justfile),
|
2020-03-13 22:19:43 -07:00
|
|
|
Variables => Self::variables(justfile),
|
2020-02-20 06:07:25 -08:00
|
|
|
Completions { .. } | Edit | Init => unreachable!(),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
fn dump(justfile: Justfile) -> Result<(), i32> {
|
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
|
|
|
println!("{}", justfile);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
pub(crate) fn edit(search: &Search) -> Result<(), i32> {
|
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 editor = env::var_os("VISUAL")
|
|
|
|
.or_else(|| env::var_os("EDITOR"))
|
|
|
|
.unwrap_or_else(|| "vim".into());
|
|
|
|
|
|
|
|
let error = Command::new(&editor)
|
|
|
|
.current_dir(&search.working_directory)
|
|
|
|
.arg(&search.justfile)
|
|
|
|
.status();
|
|
|
|
|
|
|
|
match error {
|
2020-02-10 20:07:06 -08:00
|
|
|
Ok(status) =>
|
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 status.success() {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
eprintln!("Editor `{}` failed: {}", editor.to_string_lossy(), status);
|
|
|
|
Err(status.code().unwrap_or(EXIT_FAILURE))
|
2020-02-10 20:07:06 -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
|
|
|
Err(error) => {
|
|
|
|
eprintln!(
|
|
|
|
"Editor `{}` invocation failed: {}",
|
|
|
|
editor.to_string_lossy(),
|
|
|
|
error
|
|
|
|
);
|
|
|
|
Err(EXIT_FAILURE)
|
2020-02-10 20:07:06 -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
|
|
|
pub(crate) fn init(&self) -> Result<(), i32> {
|
|
|
|
let search =
|
|
|
|
Search::init(&self.search_config, &self.invocation_directory).eprint(self.color)?;
|
|
|
|
|
|
|
|
if search.justfile.exists() {
|
|
|
|
eprintln!("Justfile `{}` already exists", search.justfile.display());
|
|
|
|
Err(EXIT_FAILURE)
|
|
|
|
} else if let Err(err) = fs::write(&search.justfile, INIT_JUSTFILE) {
|
|
|
|
eprintln!(
|
|
|
|
"Failed to write justfile to `{}`: {}",
|
|
|
|
search.justfile.display(),
|
|
|
|
err
|
|
|
|
);
|
|
|
|
Err(EXIT_FAILURE)
|
|
|
|
} else {
|
|
|
|
eprintln!("Wrote justfile to `{}`", search.justfile.display());
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
fn list(&self, justfile: Justfile) -> Result<(), i32> {
|
|
|
|
// Construct a target to alias map.
|
|
|
|
let mut recipe_aliases: BTreeMap<&str, Vec<&str>> = BTreeMap::new();
|
|
|
|
for alias in justfile.aliases.values() {
|
|
|
|
if alias.is_private() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-11-21 07:39:32 -08:00
|
|
|
if !recipe_aliases.contains_key(alias.target.name.lexeme()) {
|
|
|
|
recipe_aliases.insert(alias.target.name.lexeme(), vec![alias.name.lexeme()]);
|
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
|
|
|
} else {
|
2019-11-21 07:39:32 -08:00
|
|
|
let aliases = recipe_aliases.get_mut(alias.target.name.lexeme()).unwrap();
|
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
|
|
|
aliases.push(alias.name.lexeme());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut line_widths: BTreeMap<&str, usize> = BTreeMap::new();
|
|
|
|
|
|
|
|
for (name, recipe) in &justfile.recipes {
|
|
|
|
if recipe.private {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for name in iter::once(name).chain(recipe_aliases.get(name).unwrap_or(&Vec::new())) {
|
|
|
|
let mut line_width = UnicodeWidthStr::width(*name);
|
|
|
|
|
|
|
|
for parameter in &recipe.parameters {
|
|
|
|
line_width += UnicodeWidthStr::width(format!(" {}", parameter).as_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if line_width <= 30 {
|
|
|
|
line_widths.insert(name, line_width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let max_line_width = cmp::min(line_widths.values().cloned().max().unwrap_or(0), 30);
|
|
|
|
|
|
|
|
let doc_color = self.color.stdout().doc();
|
|
|
|
println!("Available recipes:");
|
|
|
|
|
|
|
|
for (name, recipe) in &justfile.recipes {
|
|
|
|
if recipe.private {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let alias_doc = format!("alias for `{}`", recipe.name);
|
|
|
|
|
|
|
|
for (i, name) in iter::once(name)
|
|
|
|
.chain(recipe_aliases.get(name).unwrap_or(&Vec::new()))
|
|
|
|
.enumerate()
|
|
|
|
{
|
|
|
|
print!(" {}", name);
|
|
|
|
for parameter in &recipe.parameters {
|
|
|
|
if self.color.stdout().active() {
|
|
|
|
print!(" {:#}", parameter);
|
|
|
|
} else {
|
|
|
|
print!(" {}", parameter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 04:49:25 -08:00
|
|
|
// Declaring this outside of the nested loops will probably be more efficient,
|
|
|
|
// but it creates all sorts of lifetime issues with variables inside the loops.
|
|
|
|
// If this is inlined like the docs say, it shouldn't make any difference.
|
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 print_doc = |doc| {
|
|
|
|
print!(
|
|
|
|
" {:padding$}{} {}",
|
|
|
|
"",
|
|
|
|
doc_color.paint("#"),
|
|
|
|
doc_color.paint(doc),
|
|
|
|
padding = max_line_width
|
|
|
|
.saturating_sub(line_widths.get(name).cloned().unwrap_or(max_line_width))
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
match (i, recipe.doc) {
|
|
|
|
(0, Some(doc)) => print_doc(doc),
|
|
|
|
(0, None) => (),
|
|
|
|
_ => print_doc(&alias_doc),
|
|
|
|
}
|
|
|
|
println!();
|
|
|
|
}
|
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
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
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
|
|
|
fn run(
|
|
|
|
&self,
|
|
|
|
justfile: Justfile,
|
2019-12-25 06:12:06 -08:00
|
|
|
search: &Search,
|
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: &BTreeMap<String, String>,
|
2019-11-12 14:11:53 -08:00
|
|
|
arguments: &[String],
|
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
|
|
|
) -> Result<(), i32> {
|
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 let Err(error) = InterruptHandler::install() {
|
|
|
|
warn!("Failed to set CTRL-C handler: {}", error)
|
|
|
|
}
|
|
|
|
|
2019-12-25 06:12:06 -08:00
|
|
|
let result = justfile.run(&self, search, overrides, arguments);
|
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 !self.quiet {
|
|
|
|
result.eprint(self.color)
|
|
|
|
} else {
|
|
|
|
result.map_err(|err| err.code())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
fn show(name: &str, justfile: Justfile) -> Result<(), i32> {
|
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 let Some(alias) = justfile.get_alias(name) {
|
2019-11-21 07:39:32 -08:00
|
|
|
let recipe = justfile.get_recipe(alias.target.name.lexeme()).unwrap();
|
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
|
|
|
println!("{}", alias);
|
|
|
|
println!("{}", recipe);
|
|
|
|
Ok(())
|
|
|
|
} else if let Some(recipe) = justfile.get_recipe(name) {
|
|
|
|
println!("{}", recipe);
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
eprintln!("Justfile does not contain recipe `{}`.", name);
|
|
|
|
if let Some(suggestion) = justfile.suggest(name) {
|
2020-04-26 14:19:21 -07:00
|
|
|
eprintln!("{}", suggestion);
|
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
|
|
|
}
|
|
|
|
Err(EXIT_FAILURE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
fn summary(justfile: Justfile) -> Result<(), i32> {
|
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.count() == 0 {
|
|
|
|
eprintln!("Justfile contains no recipes.");
|
|
|
|
} else {
|
|
|
|
let summary = justfile
|
|
|
|
.recipes
|
|
|
|
.iter()
|
|
|
|
.filter(|&(_, recipe)| !recipe.private)
|
|
|
|
.map(|(name, _)| name)
|
|
|
|
.cloned()
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(" ");
|
|
|
|
println!("{}", summary);
|
|
|
|
}
|
|
|
|
Ok(())
|
2019-10-07 02:06:45 -07:00
|
|
|
}
|
2020-03-13 22:19:43 -07:00
|
|
|
|
|
|
|
fn variables(justfile: Justfile) -> Result<(), i32> {
|
|
|
|
for (i, (_, assignment)) in justfile.assignments.iter().enumerate() {
|
|
|
|
if i > 0 {
|
|
|
|
print!(" ");
|
|
|
|
}
|
|
|
|
print!("{}", assignment.name)
|
|
|
|
}
|
|
|
|
println!();
|
|
|
|
Ok(())
|
|
|
|
}
|
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;
|
|
|
|
|
2020-02-14 04:49:25 -08:00
|
|
|
// This test guards against unintended changes to the argument parser. We should
|
|
|
|
// have proper tests for all the flags, but this will do for now.
|
2019-10-31 17:39:25 -07:00
|
|
|
#[test]
|
|
|
|
fn help() {
|
2020-07-19 05:10:38 -07:00
|
|
|
const EXPECTED_HELP: &str = "just v0.7.1
|
2019-10-31 17:39:25 -07:00
|
|
|
Casey Rodarmor <casey@rodarmor.com>
|
2020-02-10 20:07:06 -08:00
|
|
|
🤖 Just a command runner \
|
|
|
|
- https://github.com/casey/just
|
2019-10-31 17:39:25 -07:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
just [FLAGS] [OPTIONS] [--] [ARGUMENTS]...
|
|
|
|
|
|
|
|
FLAGS:
|
2019-11-22 11:33:56 -08:00
|
|
|
--clear-shell-args Clear shell arguments
|
|
|
|
--dry-run Print what just would do without doing it
|
|
|
|
--dump Print entire justfile
|
2020-02-10 20:07:06 -08:00
|
|
|
-e, --edit Edit justfile with editor given by $VISUAL or $EDITOR, falling back \
|
|
|
|
to `vim`
|
2019-11-22 11:33:56 -08:00
|
|
|
--evaluate Print evaluated variables
|
|
|
|
--highlight Highlight echoed recipe lines in bold
|
|
|
|
--init Initialize new justfile in project root
|
|
|
|
-l, --list List available recipes and their arguments
|
2020-05-23 20:41:12 -07:00
|
|
|
--no-dotenv Don't load `.env` file
|
2019-11-22 11:33:56 -08:00
|
|
|
--no-highlight Don't highlight echoed recipe lines in bold
|
|
|
|
-q, --quiet Suppress all output
|
|
|
|
--summary List names of available recipes
|
2020-03-13 22:19:43 -07:00
|
|
|
--variables List names of variables
|
2019-11-22 11:33:56 -08:00
|
|
|
-v, --verbose Use verbose output
|
2019-10-31 17:39:25 -07:00
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
--color <COLOR>
|
|
|
|
Print colorful output [default: auto] [possible values: auto, always, never]
|
|
|
|
|
2020-01-15 01:20:38 -08:00
|
|
|
--completions <SHELL>
|
2020-02-10 20:07:06 -08:00
|
|
|
Print shell completion script for <SHELL> [possible values: zsh, bash, fish, \
|
|
|
|
powershell, elvish]
|
2020-01-15 01:20:38 -08:00
|
|
|
|
2019-10-31 17:39:25 -07:00
|
|
|
-f, --justfile <JUSTFILE> Use <JUSTFILE> as justfile.
|
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
|
|
|
--set <VARIABLE> <VALUE> Override <VARIABLE> with <VALUE>
|
2019-10-31 17:39:25 -07:00
|
|
|
--shell <SHELL> Invoke <SHELL> to run recipes [default: sh]
|
2020-02-10 20:07:06 -08:00
|
|
|
--shell-arg <SHELL-ARG>... Invoke shell with <SHELL-ARG> as an argument \
|
|
|
|
[default: -cu]
|
2019-10-31 17:39:25 -07:00
|
|
|
-s, --show <RECIPE> Show information about <RECIPE>
|
|
|
|
-d, --working-directory <WORKING-DIRECTORY>
|
|
|
|
Use <WORKING-DIRECTORY> as working directory. --justfile must also be set
|
|
|
|
|
|
|
|
|
|
|
|
ARGS:
|
2020-02-10 20:07:06 -08:00
|
|
|
<ARGUMENTS>... Overrides and recipe(s) to run, defaulting to the first recipe in the \
|
|
|
|
justfile";
|
2019-10-31 17:39:25 -07:00
|
|
|
|
|
|
|
let app = Config::app().setting(AppSettings::ColorNever);
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
app.write_help(&mut buffer).unwrap();
|
|
|
|
let help = str::from_utf8(&buffer).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(help, EXPECTED_HELP);
|
|
|
|
}
|
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,)?
|
|
|
|
$(highlight: $highlight:expr,)?
|
|
|
|
$(quiet: $quiet:expr,)?
|
|
|
|
$(search_config: $search_config:expr,)?
|
|
|
|
$(shell: $shell:expr,)?
|
2019-11-22 11:33:56 -08:00
|
|
|
$(shell_args: $shell_args:expr,)?
|
|
|
|
$(shell_present: $shell_present: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,)?
|
|
|
|
$(verbosity: $verbosity:expr,)?
|
|
|
|
} => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
let arguments = &[
|
|
|
|
"just",
|
|
|
|
$($arg,)*
|
|
|
|
];
|
|
|
|
|
|
|
|
let want = Config {
|
|
|
|
$(color: $color,)?
|
|
|
|
$(dry_run: $dry_run,)?
|
|
|
|
$(highlight: $highlight,)?
|
|
|
|
$(quiet: $quiet,)?
|
|
|
|
$(search_config: $search_config,)?
|
|
|
|
$(shell: $shell.to_string(),)?
|
2019-11-22 11:33:56 -08:00
|
|
|
$(shell_args: $shell_args,)?
|
|
|
|
$(shell_present: $shell_present,)?
|
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,)?
|
|
|
|
$(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)
|
|
|
|
.expect("agument parsing failed");
|
|
|
|
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();
|
|
|
|
|
|
|
|
let matches = app.get_matches_from_safe(arguments).expect("Matching failes");
|
|
|
|
|
|
|
|
match Config::from_matches(&matches).expect_err("config parsing succeeded") {
|
|
|
|
$error => { $($check)? }
|
|
|
|
other => panic!("Unexpected config error: {}", other),
|
|
|
|
}
|
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! {
|
|
|
|
name: dry_run_true,
|
|
|
|
args: ["--dry-run"],
|
|
|
|
dry_run: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: quiet_default,
|
|
|
|
args: [],
|
|
|
|
quiet: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: quiet_long,
|
|
|
|
args: ["--quiet"],
|
|
|
|
quiet: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: quiet_short,
|
|
|
|
args: ["-q"],
|
|
|
|
quiet: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
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: [],
|
|
|
|
shell: "sh",
|
2019-11-22 11:33:56 -08:00
|
|
|
shell_args: vec!["-cu".to_owned()],
|
|
|
|
shell_present: false,
|
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"],
|
|
|
|
shell: "tclsh",
|
2019-11-22 11:33:56 -08:00
|
|
|
shell_present: 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: 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
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
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!{},
|
|
|
|
},
|
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"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
arguments: vec!["=foo".to_string()],
|
|
|
|
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: [],
|
|
|
|
shell_args: vec!["-cu".to_owned()],
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_hyphen,
|
|
|
|
args: ["--shell-arg", "--foo"],
|
|
|
|
shell_args: vec!["--foo".to_owned()],
|
|
|
|
shell_present: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_word,
|
|
|
|
args: ["--shell-arg", "foo"],
|
|
|
|
shell_args: vec!["foo".to_owned()],
|
|
|
|
shell_present: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_multiple,
|
|
|
|
args: ["--shell-arg", "foo", "--shell-arg", "bar"],
|
|
|
|
shell_args: vec!["foo".to_owned(), "bar".to_owned()],
|
|
|
|
shell_present: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_clear,
|
|
|
|
args: ["--clear-shell-args"],
|
|
|
|
shell_args: vec![],
|
|
|
|
shell_present: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_clear_and_set,
|
|
|
|
args: ["--clear-shell-args", "--shell-arg", "bar"],
|
|
|
|
shell_args: vec!["bar".to_owned()],
|
|
|
|
shell_present: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_and_clear,
|
|
|
|
args: ["--shell-arg", "bar", "--clear-shell-args"],
|
|
|
|
shell_args: vec![],
|
|
|
|
shell_present: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args_set_multiple_and_clear,
|
|
|
|
args: ["--shell-arg", "bar", "--shell-arg", "baz", "--clear-shell-args"],
|
|
|
|
shell_args: vec![],
|
|
|
|
shell_present: 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: 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: {
|
|
|
|
assert_eq!(subcommand, "--completions");
|
|
|
|
assert_eq!(arguments, &["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
|
|
|
error! {
|
|
|
|
name: list_arguments,
|
|
|
|
args: ["--list", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, "--list");
|
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:07:44 -08:00
|
|
|
error! {
|
|
|
|
name: evaluate_arguments,
|
|
|
|
args: ["--evaluate", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, "--evaluate");
|
|
|
|
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: dump_arguments,
|
|
|
|
args: ["--dump", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, "--dump");
|
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: edit_arguments,
|
|
|
|
args: ["--edit", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, "--edit");
|
|
|
|
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: {
|
|
|
|
assert_eq!(subcommand, "--init");
|
|
|
|
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: {
|
|
|
|
assert_eq!(subcommand, "--show");
|
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: summary_arguments,
|
|
|
|
args: ["--summary", "bar"],
|
|
|
|
error: ConfigError::SubcommandArguments { subcommand, arguments },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, "--summary");
|
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: subcommand_overrides_and_arguments,
|
|
|
|
args: ["--summary", "bar=baz", "bar"],
|
|
|
|
error: ConfigError::SubcommandOverridesAndArguments { subcommand, arguments, overrides },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, "--summary");
|
|
|
|
assert_eq!(overrides, map!{"bar": "baz"});
|
|
|
|
assert_eq!(arguments, &["bar"]);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: summary_overrides,
|
|
|
|
args: ["--summary", "bar=baz"],
|
|
|
|
error: ConfigError::SubcommandOverrides { subcommand, overrides },
|
|
|
|
check: {
|
|
|
|
assert_eq!(subcommand, "--summary");
|
|
|
|
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-11-19 23:07:44 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn init_justfile() {
|
|
|
|
testing::compile(INIT_JUSTFILE);
|
|
|
|
}
|
2019-10-31 17:39:25 -07:00
|
|
|
}
|