Compare commits

..

No commits in common. "09867c48cafab00c2a93cd7aaf5f93594c361883" and "570d3058cfc8381e03d79e93cf857c510a494f09" have entirely different histories.

23 changed files with 160 additions and 372 deletions

53
Cargo.lock generated
View File

@ -613,8 +613,6 @@ dependencies = [
"log",
"num_cpus",
"percent-encoding",
"pest",
"pest_derive",
"pretty_assertions",
"rand",
"regex",
@ -739,51 +737,6 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pest"
version = "2.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8"
dependencies = [
"memchr",
"thiserror",
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.66",
]
[[package]]
name = "pest_meta"
version = "2.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd"
dependencies = [
"once_cell",
"pest",
"sha2",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@ -1245,12 +1198,6 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "ucd-trie"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
[[package]]
name = "unicase"
version = "2.7.0"

View File

@ -37,8 +37,6 @@ libc = "0.2.0"
log = "0.4.4"
num_cpus = "1.15.0"
percent-encoding = "2.3.1"
pest = "2.7.10"
pest_derive = "2.7.10"
rand = "0.8.5"
regex = "1.10.4"
semver = "1.0.20"

View File

@ -603,9 +603,8 @@ testing… all tests passed!
Examples
--------
A variety of `justfile`s can be found in the
[examples directory](https://github.com/casey/just/tree/master/examples) and on
[GitHub](https://github.com/search?q=path%3A**%2Fjustfile&type=code).
A variety of example `justfile`s can be found in the
[examples directory](https://github.com/casey/just/tree/master/examples).
Features
--------
@ -3228,20 +3227,6 @@ mod? foo 'bar.just'
mod? foo 'baz.just'
```
Modules may be given doc comments which appear in `--list`
output<sup>master</sup>:
```mf
# foo is a great module!
mod foo
```
```sh
$ just --list
Available recipes:
foo ... # foo is a great module!
```
See the
[module stabilization tracking issue](https://github.com/casey/just/issues/929)
for more information.

View File

@ -9,24 +9,22 @@ pub(crate) struct Analyzer<'src> {
impl<'src> Analyzer<'src> {
pub(crate) fn analyze(
asts: &HashMap<PathBuf, Ast<'src>>,
doc: Option<&'src str>,
loaded: &[PathBuf],
name: Option<Name<'src>>,
paths: &HashMap<PathBuf, PathBuf>,
asts: &HashMap<PathBuf, Ast<'src>>,
root: &Path,
name: Option<Name<'src>>,
) -> CompileResult<'src, Justfile<'src>> {
Self::default().justfile(asts, doc, loaded, name, paths, root)
Self::default().justfile(loaded, paths, asts, root, name)
}
fn justfile(
mut self,
asts: &HashMap<PathBuf, Ast<'src>>,
doc: Option<&'src str>,
loaded: &[PathBuf],
name: Option<Name<'src>>,
paths: &HashMap<PathBuf, PathBuf>,
asts: &HashMap<PathBuf, Ast<'src>>,
root: &Path,
name: Option<Name<'src>>,
) -> CompileResult<'src, Justfile<'src>> {
let mut recipes = Vec::new();
@ -86,22 +84,10 @@ impl<'src> Analyzer<'src> {
stack.push(asts.get(absolute).unwrap());
}
}
Item::Module {
absolute,
name,
doc,
..
} => {
Item::Module { absolute, name, .. } => {
if let Some(absolute) = absolute {
define(*name, "module", false)?;
modules.insert(Self::analyze(
asts,
*doc,
loaded,
Some(*name),
paths,
absolute,
)?);
modules.insert(Self::analyze(loaded, paths, asts, absolute, Some(*name))?);
}
}
Item::Recipe(recipe) => {
@ -186,7 +172,6 @@ impl<'src> Analyzer<'src> {
Rc::clone(next)
}),
}),
doc,
loaded: loaded.into(),
modules,
name,

View File

@ -38,7 +38,6 @@ impl Color {
}
}
#[cfg(test)]
pub(crate) fn always() -> Self {
Self {
use_color: UseColor::Always,
@ -134,15 +133,6 @@ impl Color {
}
}
impl From<UseColor> for Color {
fn from(use_color: UseColor) -> Self {
Self {
use_color,
..Default::default()
}
}
}
impl Default for Color {
fn default() -> Self {
Self {

View File

@ -1,26 +0,0 @@
use super::*;
#[derive(Copy, Clone, ValueEnum)]
pub(crate) enum CommandColor {
Black,
Blue,
Cyan,
Green,
Purple,
Red,
Yellow,
}
impl From<CommandColor> for ansi_term::Color {
fn from(command_color: CommandColor) -> Self {
match command_color {
CommandColor::Black => Self::Black,
CommandColor::Blue => Self::Blue,
CommandColor::Cyan => Self::Cyan,
CommandColor::Green => Self::Green,
CommandColor::Purple => Self::Purple,
CommandColor::Red => Self::Red,
CommandColor::Yellow => Self::Yellow,
}
}
}

View File

@ -40,7 +40,6 @@ impl Compiler {
name,
optional,
relative,
..
} => {
if !unstable {
return Err(Error::Unstable {
@ -108,7 +107,7 @@ impl Compiler {
asts.insert(current.path, ast.clone());
}
let justfile = Analyzer::analyze(&asts, None, &loaded, None, &paths, root)?;
let justfile = Analyzer::analyze(&loaded, &paths, &asts, root, None)?;
Ok(Compilation {
asts,
@ -185,7 +184,7 @@ impl Compiler {
asts.insert(root.clone(), ast);
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
paths.insert(root.clone(), root.clone());
Analyzer::analyze(&asts, None, &[], None, &paths, &root)
Analyzer::analyze(&[], &paths, &asts, &root, None)
}
}

View File

@ -1,4 +1,4 @@
use super::*;
use {super::*, clap::ValueEnum};
#[derive(ValueEnum, Debug, Clone, Copy, PartialEq)]
pub(crate) enum Shell {
@ -255,7 +255,7 @@ const POWERSHELL_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[(
r#"function Get-JustFileRecipes([string[]]$CommandElements) {
$justFileIndex = $commandElements.IndexOf("--justfile");
if ($justFileIndex -ne -1 -and $justFileIndex + 1 -le $commandElements.Length) {
if ($justFileIndex -ne -1 && $justFileIndex + 1 -le $commandElements.Length) {
$justFileLocation = $commandElements[$justFileIndex + 1]
}

View File

@ -1,7 +1,7 @@
use {
super::*,
clap::{
builder::{styling::AnsiColor, FalseyValueParser, Styles},
builder::{styling::AnsiColor, FalseyValueParser, PossibleValuesParser, Styles},
parser::ValuesRef,
value_parser, Arg, ArgAction, ArgGroup, ArgMatches, Command,
},
@ -108,6 +108,32 @@ mod arg {
pub(crate) const VERBOSE: &str = "VERBOSE";
pub(crate) const WORKING_DIRECTORY: &str = "WORKING-DIRECTORY";
pub(crate) const YES: &str = "YES";
pub(crate) const COLOR_ALWAYS: &str = "always";
pub(crate) const COLOR_AUTO: &str = "auto";
pub(crate) const COLOR_NEVER: &str = "never";
pub(crate) const COLOR_VALUES: &[&str] = &[COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER];
pub(crate) const COMMAND_COLOR_BLACK: &str = "black";
pub(crate) const COMMAND_COLOR_BLUE: &str = "blue";
pub(crate) const COMMAND_COLOR_CYAN: &str = "cyan";
pub(crate) const COMMAND_COLOR_GREEN: &str = "green";
pub(crate) const COMMAND_COLOR_PURPLE: &str = "purple";
pub(crate) const COMMAND_COLOR_RED: &str = "red";
pub(crate) const COMMAND_COLOR_YELLOW: &str = "yellow";
pub(crate) const COMMAND_COLOR_VALUES: &[&str] = &[
COMMAND_COLOR_BLACK,
COMMAND_COLOR_BLUE,
COMMAND_COLOR_CYAN,
COMMAND_COLOR_GREEN,
COMMAND_COLOR_PURPLE,
COMMAND_COLOR_RED,
COMMAND_COLOR_YELLOW,
];
pub(crate) const DUMP_FORMAT_JSON: &str = "json";
pub(crate) const DUMP_FORMAT_JUST: &str = "just";
pub(crate) const DUMP_FORMAT_VALUES: &[&str] = &[DUMP_FORMAT_JUST, DUMP_FORMAT_JSON];
}
impl Config {
@ -158,8 +184,8 @@ impl Config {
.long("color")
.env("JUST_COLOR")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(UseColor))
.default_value("auto")
.value_parser(PossibleValuesParser::new(arg::COLOR_VALUES))
.default_value(arg::COLOR_AUTO)
.help("Print colorful output"),
)
.arg(
@ -167,7 +193,7 @@ impl Config {
.long("command-color")
.env("JUST_COMMAND_COLOR")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(CommandColor))
.value_parser(PossibleValuesParser::new(arg::COMMAND_COLOR_VALUES))
.help("Echo recipe lines in <COMMAND-COLOR>"),
)
.arg(
@ -199,8 +225,8 @@ impl Config {
.long("dump-format")
.env("JUST_DUMP_FORMAT")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(DumpFormat))
.default_value("just")
.value_parser(PossibleValuesParser::new(arg::DUMP_FORMAT_VALUES))
.default_value(arg::DUMP_FORMAT_JUST)
.value_name("FORMAT")
.help("Dump justfile as <FORMAT>"),
)
@ -236,7 +262,6 @@ impl Config {
.env("JUST_LIST_HEADING")
.help("Print <TEXT> before list")
.value_name("TEXT")
.default_value("Available recipes:\n")
.action(ArgAction::Set),
)
.arg(
@ -245,7 +270,6 @@ impl Config {
.env("JUST_LIST_PREFIX")
.help("Print <TEXT> before each list item")
.value_name("TEXT")
.default_value(" ")
.action(ArgAction::Set),
)
.arg(
@ -507,6 +531,59 @@ impl Config {
)
}
fn color_from_matches(matches: &ArgMatches) -> ConfigResult<Color> {
let value = matches
.get_one::<String>(arg::COLOR)
.ok_or_else(|| ConfigError::Internal {
message: "`--color` had no value".to_string(),
})?;
match value.as_str() {
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 `{value}` to --color."),
}),
}
}
fn command_color_from_matches(matches: &ArgMatches) -> ConfigResult<Option<ansi_term::Color>> {
if let Some(value) = matches.get_one::<String>(arg::COMMAND_COLOR) {
match value.as_str() {
arg::COMMAND_COLOR_BLACK => Ok(Some(ansi_term::Color::Black)),
arg::COMMAND_COLOR_BLUE => Ok(Some(ansi_term::Color::Blue)),
arg::COMMAND_COLOR_CYAN => Ok(Some(ansi_term::Color::Cyan)),
arg::COMMAND_COLOR_GREEN => Ok(Some(ansi_term::Color::Green)),
arg::COMMAND_COLOR_PURPLE => Ok(Some(ansi_term::Color::Purple)),
arg::COMMAND_COLOR_RED => Ok(Some(ansi_term::Color::Red)),
arg::COMMAND_COLOR_YELLOW => Ok(Some(ansi_term::Color::Yellow)),
value => Err(ConfigError::Internal {
message: format!("Invalid argument `{value}` to --command-color."),
}),
}
} else {
Ok(None)
}
}
fn dump_format_from_matches(matches: &ArgMatches) -> ConfigResult<DumpFormat> {
let value =
matches
.get_one::<String>(arg::DUMP_FORMAT)
.ok_or_else(|| ConfigError::Internal {
message: "`--dump-format` had no value".to_string(),
})?;
match value.as_str() {
arg::DUMP_FORMAT_JSON => Ok(DumpFormat::Json),
arg::DUMP_FORMAT_JUST => Ok(DumpFormat::Just),
_ => Err(ConfigError::Internal {
message: format!("Invalid argument `{value}` to --dump-format."),
}),
}
}
fn parse_module_path(values: ValuesRef<String>) -> ConfigResult<ModulePath> {
let path = values.clone().map(|s| (*s).as_str()).collect::<Vec<&str>>();
@ -667,28 +744,24 @@ impl Config {
}
};
let unstable = matches.get_flag(arg::UNSTABLE) || subcommand == Subcommand::Summary;
Ok(Self {
check: matches.get_flag(arg::CHECK),
color: (*matches.get_one::<UseColor>(arg::COLOR).unwrap()).into(),
command_color: matches
.get_one::<CommandColor>(arg::COMMAND_COLOR)
.copied()
.map(CommandColor::into),
color: Self::color_from_matches(matches)?,
command_color: Self::command_color_from_matches(matches)?,
dotenv_filename: matches
.get_one::<String>(arg::DOTENV_FILENAME)
.map(Into::into),
dotenv_path: matches.get_one::<PathBuf>(arg::DOTENV_PATH).map(Into::into),
dry_run: matches.get_flag(arg::DRY_RUN),
dump_format: matches
.get_one::<DumpFormat>(arg::DUMP_FORMAT)
.unwrap()
.clone(),
dump_format: Self::dump_format_from_matches(matches)?,
highlight: !matches.get_flag(arg::NO_HIGHLIGHT),
invocation_directory: env::current_dir().context(config_error::CurrentDirContext)?,
list_heading: matches.get_one::<String>(arg::LIST_HEADING).unwrap().into(),
list_prefix: matches.get_one::<String>(arg::LIST_PREFIX).unwrap().into(),
list_heading: matches
.get_one::<String>(arg::LIST_HEADING)
.map_or_else(|| "Available recipes:\n".into(), Into::into),
list_prefix: matches
.get_one::<String>(arg::LIST_PREFIX)
.map_or_else(|| " ".into(), Into::into),
list_submodules: matches.get_flag(arg::LIST_SUBMODULES),
load_dotenv: !matches.get_flag(arg::NO_DOTENV),
no_aliases: matches.get_flag(arg::NO_ALIASES),
@ -710,7 +783,7 @@ impl Config {
.unwrap()
.into(),
unsorted: matches.get_flag(arg::UNSORTED),
unstable,
unstable: matches.get_flag(arg::UNSTABLE),
verbosity: if matches.get_flag(arg::QUIET) {
Verbosity::Quiet
} else {
@ -761,7 +834,6 @@ mod tests {
$(shell_args: $shell_args:expr,)?
$(subcommand: $subcommand:expr,)?
$(unsorted: $unsorted:expr,)?
$(unstable: $unstable:expr,)?
$(verbosity: $verbosity:expr,)?
} => {
#[test]
@ -782,7 +854,6 @@ mod tests {
$(shell_args: $shell_args,)?
$(subcommand: $subcommand,)?
$(unsorted: $unsorted,)?
$(unstable: $unstable,)?
$(verbosity: $verbosity,)?
..testing::config(&[])
};
@ -1297,7 +1368,6 @@ mod tests {
name: subcommand_summary,
args: ["--summary"],
subcommand: Subcommand::Summary,
unstable: true,
}
test! {

View File

@ -1,6 +1,4 @@
use super::*;
#[derive(Debug, PartialEq, Clone, ValueEnum)]
#[derive(Debug, PartialEq)]
pub(crate) enum DumpFormat {
Json,
Just,

View File

@ -14,7 +14,6 @@ pub(crate) enum Item<'src> {
},
Module {
absolute: Option<PathBuf>,
doc: Option<&'src str>,
name: Name<'src>,
optional: bool,
relative: Option<StringLiteral<'src>>,

View File

@ -1,9 +0,0 @@
identifier = { (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")+ }
recipe = { identifier ~ ":" ~ NEWLINE ~ recipe_body }
recipe_body = { recipe_line* }
recipe_line = {

View File

@ -13,7 +13,6 @@ struct Invocation<'src: 'run, 'run> {
pub(crate) struct Justfile<'src> {
pub(crate) aliases: Table<'src, Alias<'src>>,
pub(crate) assignments: Table<'src, Assignment<'src>>,
pub(crate) doc: Option<&'src str>,
#[serde(rename = "first", serialize_with = "keyed::serialize_option")]
pub(crate) default: Option<Rc<Recipe<'src>>>,
#[serde(skip)]

View File

@ -23,30 +23,29 @@ pub(crate) use {
crate::{
alias::Alias, analyzer::Analyzer, argument_parser::ArgumentParser, assignment::Assignment,
assignment_resolver::AssignmentResolver, ast::Ast, attribute::Attribute, binding::Binding,
color::Color, color_display::ColorDisplay, command_color::CommandColor,
command_ext::CommandExt, compilation::Compilation, compile_error::CompileError,
compile_error_kind::CompileErrorKind, compiler::Compiler, condition::Condition,
conditional_operator::ConditionalOperator, config::Config, config_error::ConfigError,
constants::constants, count::Count, delimiter::Delimiter, dependency::Dependency,
dump_format::DumpFormat, enclosure::Enclosure, error::Error, evaluator::Evaluator,
execution_context::ExecutionContext, expression::Expression, fragment::Fragment,
function::Function, interrupt_guard::InterruptGuard, interrupt_handler::InterruptHandler,
item::Item, justfile::Justfile, keyed::Keyed, keyword::Keyword, lexer::Lexer, line::Line,
list::List, load_dotenv::load_dotenv, loader::Loader, module_path::ModulePath, name::Name,
namepath::Namepath, ordinal::Ordinal, output::output, output_error::OutputError,
parameter::Parameter, parameter_kind::ParameterKind, parser::Parser, platform::Platform,
platform_interface::PlatformInterface, position::Position, positional::Positional, ran::Ran,
range_ext::RangeExt, recipe::Recipe, recipe_resolver::RecipeResolver,
recipe_signature::RecipeSignature, scope::Scope, search::Search, search_config::SearchConfig,
search_error::SearchError, set::Set, setting::Setting, settings::Settings, shebang::Shebang,
shell::Shell, show_whitespace::ShowWhitespace, source::Source, string_kind::StringKind,
color::Color, color_display::ColorDisplay, command_ext::CommandExt, compilation::Compilation,
compile_error::CompileError, compile_error_kind::CompileErrorKind, compiler::Compiler,
condition::Condition, conditional_operator::ConditionalOperator, config::Config,
config_error::ConfigError, constants::constants, count::Count, delimiter::Delimiter,
dependency::Dependency, dump_format::DumpFormat, enclosure::Enclosure, error::Error,
evaluator::Evaluator, execution_context::ExecutionContext, expression::Expression,
fragment::Fragment, function::Function, interrupt_guard::InterruptGuard,
interrupt_handler::InterruptHandler, item::Item, justfile::Justfile, keyed::Keyed,
keyword::Keyword, lexer::Lexer, line::Line, list::List, load_dotenv::load_dotenv,
loader::Loader, module_path::ModulePath, name::Name, namepath::Namepath, ordinal::Ordinal,
output::output, output_error::OutputError, parameter::Parameter, parameter_kind::ParameterKind,
parser::Parser, platform::Platform, platform_interface::PlatformInterface, position::Position,
positional::Positional, ran::Ran, range_ext::RangeExt, recipe::Recipe,
recipe_resolver::RecipeResolver, recipe_signature::RecipeSignature, scope::Scope,
search::Search, search_config::SearchConfig, search_error::SearchError, set::Set,
setting::Setting, settings::Settings, shebang::Shebang, shell::Shell,
show_whitespace::ShowWhitespace, source::Source, string_kind::StringKind,
string_literal::StringLiteral, subcommand::Subcommand, suggestion::Suggestion, table::Table,
thunk::Thunk, token::Token, token_kind::TokenKind, unresolved_dependency::UnresolvedDependency,
unresolved_recipe::UnresolvedRecipe, use_color::UseColor, variables::Variables,
verbosity::Verbosity, warning::Warning,
},
camino::Utf8Path,
clap::ValueEnum,
derivative::Derivative,
edit_distance::edit_distance,
lexiclean::Lexiclean,
@ -129,7 +128,6 @@ mod attribute;
mod binding;
mod color;
mod color_display;
mod command_color;
mod command_ext;
mod compilation;
mod compile_error;

View File

@ -36,18 +36,7 @@ pub(crate) struct Parser<'run, 'src> {
working_directory: &'run Path,
}
#[derive(pest_derive::Parser)]
#[grammar = "justfile.pest"]
struct JustfileParser;
impl<'run, 'src> Parser<'run, 'src> {
pub(crate) fn parse_new(path: &'src Path, src: &'src str) -> CompileResult<'src, Ast<'src>> {
todo!()
}
/// Parse `tokens` into an `Ast`
pub(crate) fn parse(
file_depth: u32,
@ -376,15 +365,12 @@ impl<'run, 'src> Parser<'run, 'src> {
});
}
Some(Keyword::Mod)
if self.next_are(&[Identifier, Identifier, Comment])
if self.next_are(&[Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, Identifier, Eof])
|| self.next_are(&[Identifier, Identifier, Eol])
|| self.next_are(&[Identifier, Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, QuestionMark]) =>
{
let doc = pop_doc_comment(&mut items, eol_since_last_comment);
self.presume_keyword(Keyword::Mod)?;
let optional = self.accepted(QuestionMark)?;
@ -400,7 +386,6 @@ impl<'run, 'src> Parser<'run, 'src> {
items.push(Item::Module {
absolute: None,
doc,
name,
optional,
relative,

View File

@ -435,27 +435,6 @@ impl Subcommand {
}
fn list_module(config: &Config, module: &Justfile, depth: usize) {
fn format_doc(
config: &Config,
name: &str,
doc: Option<&str>,
max_signature_width: usize,
signature_widths: &BTreeMap<&str, usize>,
) {
if let Some(doc) = doc {
if doc.lines().count() <= 1 {
print!(
"{:padding$}{} {}",
"",
config.color.stdout().doc().paint("#"),
config.color.stdout().doc().paint(doc),
padding = max_signature_width.saturating_sub(signature_widths[name]) + 1,
);
}
}
println!();
}
let aliases = if config.no_aliases {
BTreeMap::new()
} else {
@ -489,11 +468,6 @@ impl Subcommand {
);
}
}
if !config.list_submodules {
for (name, _) in &module.modules {
signature_widths.insert(name, UnicodeWidthStr::width(format!("{name} ...").as_str()));
}
}
signature_widths
};
@ -580,13 +554,18 @@ impl Subcommand {
RecipeSignature { name, recipe }.color_display(config.color.stdout())
);
format_doc(
config,
name,
doc.as_deref(),
max_signature_width,
&signature_widths,
);
if let Some(doc) = doc {
if doc.lines().count() <= 1 {
print!(
"{:padding$}{} {}",
"",
config.color.stdout().doc().paint("#"),
config.color.stdout().doc().paint(&doc),
padding = max_signature_width.saturating_sub(signature_widths[name]) + 1,
);
}
}
println!();
}
}
}
@ -603,14 +582,7 @@ impl Subcommand {
}
} else {
for submodule in module.modules(config) {
print!("{list_prefix}{} ...", submodule.name());
format_doc(
config,
submodule.name(),
submodule.doc,
max_signature_width,
&signature_widths,
);
println!("{list_prefix}{} ...", submodule.name(),);
}
}
}

View File

@ -77,7 +77,7 @@ pub(crate) fn analysis_error(
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
paths.insert("justfile".into(), "justfile".into());
match Analyzer::analyze(&asts, None, &[], None, &paths, &root) {
match Analyzer::analyze(&[], &paths, &asts, &root, None) {
Ok(_) => panic!("Analysis unexpectedly succeeded"),
Err(have) => {
let want = CompileError {

View File

@ -1,6 +1,4 @@
use super::*;
#[derive(Copy, Clone, Debug, PartialEq, ValueEnum)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum UseColor {
Auto,
Always,

View File

@ -34,10 +34,10 @@ b := env_var_or_default('ZADDY', 'HTAP')
x := env_var_or_default('XYZ', 'ABC')
foo:
/usr/bin/env echo '{{p}}' '{{b}}' '{{x}}'
/bin/echo '{{p}}' '{{b}}' '{{x}}'
"#,
stdout: format!("{} HTAP ABC\n", env::var("USER").unwrap()).as_str(),
stderr: format!("/usr/bin/env echo '{}' 'HTAP' 'ABC'\n", env::var("USER").unwrap()).as_str(),
stderr: format!("/bin/echo '{}' 'HTAP' 'ABC'\n", env::var("USER").unwrap()).as_str(),
}
#[cfg(not(windows))]
@ -52,10 +52,10 @@ ext := extension('/foo/bar/baz.hello')
jn := join('a', 'b')
foo:
/usr/bin/env echo '{{we}}' '{{fs}}' '{{fn}}' '{{dir}}' '{{ext}}' '{{jn}}'
/bin/echo '{{we}}' '{{fs}}' '{{fn}}' '{{dir}}' '{{ext}}' '{{jn}}'
"#,
stdout: "/foo/bar/baz baz baz.hello /foo/bar hello a/b\n",
stderr: "/usr/bin/env echo '/foo/bar/baz' 'baz' 'baz.hello' '/foo/bar' 'hello' 'a/b'\n",
stderr: "/bin/echo '/foo/bar/baz' 'baz' 'baz.hello' '/foo/bar' 'hello' 'a/b'\n",
}
#[cfg(not(windows))]
@ -69,10 +69,10 @@ dir := parent_directory('/foo/')
ext := extension('/foo/bar/baz.hello.ciao')
foo:
/usr/bin/env echo '{{we}}' '{{fs}}' '{{fn}}' '{{dir}}' '{{ext}}'
/bin/echo '{{we}}' '{{fs}}' '{{fn}}' '{{dir}}' '{{ext}}'
"#,
stdout: "/foo/bar/baz baz.hello baz.hello.ciao / ciao\n",
stderr: "/usr/bin/env echo '/foo/bar/baz' 'baz.hello' 'baz.hello.ciao' '/' 'ciao'\n",
stderr: "/bin/echo '/foo/bar/baz' 'baz.hello' 'baz.hello.ciao' '/' 'ciao'\n",
}
#[cfg(not(windows))]
@ -82,7 +82,7 @@ test! {
we := without_extension('')
foo:
/usr/bin/env echo '{{we}}'
/bin/echo '{{we}}'
"#,
stdout: "",
stderr: format!("{} {}\n{}\n{}\n{}\n{}\n",
@ -102,7 +102,7 @@ test! {
we := extension('')
foo:
/usr/bin/env echo '{{we}}'
/bin/echo '{{we}}'
"#,
stdout: "",
stderr: format!("{}\n{}\n{}\n{}\n{}\n",
@ -121,7 +121,7 @@ test! {
we := extension('foo')
foo:
/usr/bin/env echo '{{we}}'
/bin/echo '{{we}}'
"#,
stdout: "",
stderr: format!("{}\n{}\n{}\n{}\n{}\n",
@ -140,7 +140,7 @@ test! {
we := file_stem('')
foo:
/usr/bin/env echo '{{we}}'
/bin/echo '{{we}}'
"#,
stdout: "",
stderr: format!("{}\n{}\n{}\n{}\n{}\n",
@ -159,7 +159,7 @@ test! {
we := file_name('')
foo:
/usr/bin/env echo '{{we}}'
/bin/echo '{{we}}'
"#,
stdout: "",
stderr: format!("{}\n{}\n{}\n{}\n{}\n",
@ -178,7 +178,7 @@ test! {
we := parent_directory('')
foo:
/usr/bin/env echo '{{we}}'
/bin/echo '{{we}}'
"#,
stdout: "",
stderr: format!("{} {}\n{}\n{}\n{}\n{}\n",
@ -198,7 +198,7 @@ test! {
we := parent_directory('/')
foo:
/usr/bin/env echo '{{we}}'
/bin/echo '{{we}}'
"#,
stdout: "",
stderr: format!("{} {}\n{}\n{}\n{}\n{}\n",
@ -220,10 +220,10 @@ b := env_var_or_default('ZADDY', 'HTAP')
x := env_var_or_default('XYZ', 'ABC')
foo:
/usr/bin/env echo '{{p}}' '{{b}}' '{{x}}'
/bin/echo '{{p}}' '{{b}}' '{{x}}'
"#,
stdout: format!("{} HTAP ABC\n", env::var("USERNAME").unwrap()).as_str(),
stderr: format!("/usr/bin/env echo '{}' 'HTAP' 'ABC'\n", env::var("USERNAME").unwrap()).as_str(),
stderr: format!("/bin/echo '{}' 'HTAP' 'ABC'\n", env::var("USERNAME").unwrap()).as_str(),
}
test! {

View File

@ -18,7 +18,6 @@ fn alias() {
",
json!({
"first": "foo",
"doc": null,
"aliases": {
"f": {
"name": "f",
@ -81,7 +80,6 @@ fn assignment() {
}
},
"first": null,
"doc": null,
"modules": {},
"recipes": {},
"settings": {
@ -119,7 +117,6 @@ fn body() {
"aliases": {},
"assignments": {},
"first": "foo",
"doc": null,
"modules": {},
"recipes": {
"foo": {
@ -173,7 +170,6 @@ fn dependencies() {
"aliases": {},
"assignments": {},
"first": "foo",
"doc": null,
"modules": {},
"recipes": {
"bar": {
@ -252,7 +248,6 @@ fn dependency_argument() {
json!({
"aliases": {},
"first": "foo",
"doc": null,
"assignments": {
"x": {
"export": false,
@ -346,7 +341,6 @@ fn duplicate_recipes() {
",
json!({
"first": "foo",
"doc": null,
"aliases": {
"f": {
"attributes": [],
@ -420,7 +414,6 @@ fn duplicate_variables() {
}
},
"first": null,
"doc": null,
"modules": {},
"recipes": {},
"settings": {
@ -453,7 +446,6 @@ fn doc_comment() {
json!({
"aliases": {},
"first": "foo",
"doc": null,
"assignments": {},
"modules": {},
"recipes": {
@ -502,7 +494,6 @@ fn empty_justfile() {
"aliases": {},
"assignments": {},
"first": null,
"doc": null,
"modules": {},
"recipes": {},
"settings": {
@ -542,7 +533,6 @@ fn parameters() {
json!({
"aliases": {},
"first": "a",
"doc": null,
"assignments": {},
"modules": {},
"recipes": {
@ -695,7 +685,6 @@ fn priors() {
"aliases": {},
"assignments": {},
"first": "a",
"doc": null,
"modules": {},
"recipes": {
"a": {
@ -779,7 +768,6 @@ fn private() {
"aliases": {},
"assignments": {},
"first": "_foo",
"doc": null,
"modules": {},
"recipes": {
"_foo": {
@ -827,7 +815,6 @@ fn quiet() {
"aliases": {},
"assignments": {},
"first": "foo",
"doc": null,
"modules": {},
"recipes": {
"foo": {
@ -887,7 +874,6 @@ fn settings() {
"aliases": {},
"assignments": {},
"first": "foo",
"doc": null,
"modules": {},
"recipes": {
"foo": {
@ -941,7 +927,6 @@ fn shebang() {
"aliases": {},
"assignments": {},
"first": "foo",
"doc": null,
"modules": {},
"recipes": {
"foo": {
@ -989,7 +974,6 @@ fn simple() {
"aliases": {},
"assignments": {},
"first": "foo",
"doc": null,
"modules": {},
"recipes": {
"foo": {
@ -1040,7 +1024,6 @@ fn attribute() {
"aliases": {},
"assignments": {},
"first": "foo",
"doc": null,
"modules": {},
"recipes": {
"foo": {
@ -1085,7 +1068,6 @@ fn module() {
Test::new()
.justfile(
"
# hello
mod foo
",
)
@ -1100,13 +1082,11 @@ fn module() {
"aliases": {},
"assignments": {},
"first": null,
"doc": null,
"modules": {
"foo": {
"aliases": {},
"assignments": {},
"first": "bar",
"doc": "hello",
"modules": {},
"recipes": {
"bar": {

View File

@ -353,55 +353,3 @@ fn nested_modules_are_properly_indented() {
)
.run();
}
#[test]
fn module_doc_rendered() {
Test::new()
.write("foo.just", "")
.justfile(
"
# Module foo
mod foo
",
)
.test_round_trip(false)
.args(["--unstable", "--list"])
.stdout(
"
Available recipes:
foo ... # Module foo
",
)
.run();
}
#[test]
fn module_doc_aligned() {
Test::new()
.write("foo.just", "")
.write("bar.just", "")
.justfile(
"
# Module foo
mod foo
# comment
mod very_long_name_for_module \"bar.just\" # comment
# will change your world
recipe:
@echo Hi
",
)
.test_round_trip(false)
.args(["--unstable", "--list"])
.stdout(
"
Available recipes:
recipe # will change your world
foo ... # Module foo
very_long_name_for_module ... # comment
",
)
.run();
}

View File

@ -8,6 +8,8 @@ fn modules_are_unstable() {
mod foo
",
)
.arg("foo")
.arg("foo")
.stderr(
"error: Modules are currently unstable. \
Invoke `just` with the `--unstable` flag to enable unstable features.\n",
@ -779,18 +781,3 @@ fn colon_separated_path_components_are_not_used_as_arguments() {
.status(1)
.run();
}
#[test]
fn comments_can_follow_modules() {
Test::new()
.write("foo.just", "foo:\n @echo FOO")
.justfile(
"
mod foo # this is foo
",
)
.test_round_trip(false)
.args(["--unstable", "foo", "foo"])
.stdout("FOO\n")
.run();
}

View File

@ -71,18 +71,3 @@ fn submodule_recipes() {
.stdout("bar foo::foo foo::bar::bar foo::bar::baz::baz foo::bar::baz::biz::biz\n")
.run();
}
#[test]
fn summary_implies_unstable() {
Test::new()
.write("foo.just", "foo:")
.justfile(
"
mod foo
",
)
.test_round_trip(false)
.arg("--summary")
.stdout("foo::foo\n")
.run();
}