just/src/config_error.rs
Casey Rodarmor 177516bcbe
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

60 lines
1.7 KiB
Rust

use crate::common::*;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub(crate) enum ConfigError {
#[snafu(display(
"Internal config error, this may indicate a bug in just: {} \
consider filing an issue: https://github.com/casey/just/issues/new",
message
))]
Internal { message: String },
#[snafu(display("Could not canonicalize justfile path `{}`: {}", path.display(), source))]
JustfilePathCanonicalize { path: PathBuf, source: io::Error },
#[snafu(display("Failed to get current directory: {}", source))]
CurrentDir { source: io::Error },
#[snafu(display(
"Path-prefixed recipes may not be used with `--working-directory` or `--justfile`."
))]
SearchDirConflict,
#[snafu(display(
"`{}` used with unexpected arguments: {}",
subcommand,
List::and_ticked(arguments)
))]
SubcommandArguments {
subcommand: String,
arguments: Vec<String>,
},
#[snafu(display(
"`{}` used with unexpected overrides: {}; and arguments: {}",
subcommand,
List::and_ticked(overrides.iter().map(|(key, value)| format!("{}={}", key, value))),
List::and_ticked(arguments)))
]
SubcommandOverridesAndArguments {
subcommand: String,
overrides: BTreeMap<String, String>,
arguments: Vec<String>,
},
#[snafu(display(
"`{}` used with unexpected overrides: {}",
subcommand,
List::and_ticked(overrides.iter().map(|(key, value)| format!("{}={}", key, value))),
))]
SubcommandOverrides {
subcommand: String,
overrides: BTreeMap<String, String>,
},
}
impl ConfigError {
pub(crate) fn internal(message: impl Into<String>) -> ConfigError {
ConfigError::Internal {
message: message.into(),
}
}
}
impl Error for ConfigError {}