Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tasks): optional automatic outputs #3528

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/.vitepress/cli_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export const commands: { [key: string]: Command } = {
},
doctor: {
hide: false,
subcommands: {
path: {
hide: false,
},
},
},
en: {
hide: false,
Expand Down
6 changes: 5 additions & 1 deletion docs/cli/doctor.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# `mise doctor`

- **Usage**: `mise doctor`
- **Usage**: `mise doctor <SUBCOMMAND>`
- **Aliases**: `dr`
- **Source code**: [`src/cli/doctor.rs`](https://github.com/jdx/mise/blob/main/src/cli/doctor.rs)

Check mise installation for possible problems

## Subcommands

- [`mise doctor path [-f --full]`](/cli/doctor/path.md)

Examples:

$ mise doctor
Expand Down
20 changes: 20 additions & 0 deletions docs/cli/doctor/path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# `mise doctor path`

- **Usage**: `mise doctor path [-f --full]`
- **Source code**: [`src/cli/doctor/path.rs`](https://github.com/jdx/mise/blob/main/src/cli/doctor/path.rs)

Print the current PATH entries mise is providing

## Flags

### `-f --full`

Print all entries including those not provided by mise

Examples:

Get the current PATH entries mise is providing
$ mise path
/home/user/.local/share/mise/installs/node/24.0.0/bin
/home/user/.local/share/mise/installs/rust/1.90.0/bin
/home/user/.local/share/mise/installs/python/3.10.0/bin
19 changes: 9 additions & 10 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,26 @@ Set the environment for loading `mise.<ENV>.toml`

How many jobs to run in parallel [default: 8]

### `-q --quiet`

Suppress non-error messages

### `--raw`

Read/write directly to stdin/stdout/stderr instead of by line

### `-v --verbose...`

Show extra output (use -vv for even more)

### `-y --yes`

Answer yes to all confirmation prompts

## Flags
### `-q --quiet`

Suppress non-error messages

### `--silent`

Suppress all task output and mise non-error messages

### `-v --verbose...`

Show extra output (use -vv for even more)

## Subcommands

- [`mise activate [FLAGS] [SHELL_TYPE]`](/cli/activate.md)
Expand All @@ -69,7 +67,8 @@ Suppress all task output and mise non-error messages
- [`mise config ls [--no-header] [-J --json]`](/cli/config/ls.md)
- [`mise config set [-f --file <FILE>] [-t --type <TYPE>] <KEY> <VALUE>`](/cli/config/set.md)
- [`mise deactivate`](/cli/deactivate.md)
- [`mise doctor`](/cli/doctor.md)
- [`mise doctor <SUBCOMMAND>`](/cli/doctor.md)
- [`mise doctor path [-f --full]`](/cli/doctor/path.md)
- [`mise en [-s --shell <SHELL>] [DIR]`](/cli/en.md)
- [`mise env [FLAGS] [TOOL@VERSION]...`](/cli/env.md)
- [`mise exec [FLAGS] [TOOL@VERSION]... [COMMAND]...`](/cli/exec.md)
Expand Down
14 changes: 14 additions & 0 deletions e2e/tasks/test_task_run_sources
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@ assert_empty "mise -q hi"
assert_empty "mise -q hi"
touch ../older
assert "mise -q hi" "hi"

cat <<EOF >mise.toml
[tasks.hi]
sources = ["{{cwd}}/input"]
outputs = { auto = true }
run = "echo hi"
EOF

mkdir subdir && cd subdir || exit 1
assert "mise -q hi" "hi"
assert_empty "mise -q hi"
touch input
assert "mise -q hi" "hi"
assert_empty "mise -q hi"
14 changes: 7 additions & 7 deletions man/man1/mise.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH NAME
mise \- The front\-end to your dev env
.SH SYNOPSIS
\fBmise\fR [\fB\-C\fR|\fB\-\-cd\fR] [\fB\-E\fR|\fB\-\-env\fR] [\fB\-j\fR|\fB\-\-jobs\fR] [\fB\-q\fR|\fB\-\-quiet\fR] [\fB\-\-raw\fR] [\fB\-\-silent\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-y\fR|\fB\-\-yes\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fITASK\fR] [\fITASK_ARGS\fR] [\fIsubcommands\fR]
\fBmise\fR [\fB\-C\fR|\fB\-\-cd\fR] [\fB\-E\fR|\fB\-\-env\fR] [\fB\-j\fR|\fB\-\-jobs\fR] [\fB\-\-raw\fR] [\fB\-y\fR|\fB\-\-yes\fR] [\fB\-q\fR|\fB\-\-quiet\fR] [\fB\-\-silent\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-h\fR|\fB\-\-help\fR] [\fITASK\fR] [\fITASK_ARGS\fR] [\fIsubcommands\fR]
.SH DESCRIPTION
.PP
mise is a tool for managing runtime versions. https://github.com/jdx/mise
Expand All @@ -29,21 +29,21 @@ How many jobs to run in parallel [default: 8]
May also be specified with the \fBMISE_JOBS\fR environment variable.
.RE
.TP
\fB\-q\fR, \fB\-\-quiet\fR
Suppress non\-error messages
.TP
\fB\-\-raw\fR
Read/write directly to stdin/stdout/stderr instead of by line
.TP
\fB\-y\fR, \fB\-\-yes\fR
Answer yes to all confirmation prompts
.TP
\fB\-q\fR, \fB\-\-quiet\fR
Suppress non\-error messages
.TP
\fB\-\-silent\fR
Suppress all task output and mise non\-error messages
.TP
\fB\-v\fR, \fB\-\-verbose\fR
Show extra output (use \-vv for even more)
.TP
\fB\-y\fR, \fB\-\-yes\fR
Answer yes to all confirmation prompts
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help (see a summary with \*(Aq\-h\*(Aq)
.TP
Expand Down
31 changes: 21 additions & 10 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ flag "-C --cd" help="Change directory before running command" global=true {
arg "<DIR>"
}
flag "-n --dry-run" help="Dry run, don't actually do anything" hide=true
flag "--debug" help="Sets log level to debug" hide=true global=true
flag "-E --env" help="Set the environment for loading `mise.<ENV>.toml`" var=true global=true {
arg "<ENV>"
}
Expand All @@ -25,11 +24,6 @@ flag "-i --interleave" help="Set the log output verbosity" hide=true
flag "-j --jobs" help="How many jobs to run in parallel [default: 8]" global=true {
arg "<JOBS>"
}
flag "--log-level" hide=true global=true {
arg "<LEVEL>" {
choices "trace" "debug" "info" "warning" "error"
}
}
flag "-p --prefix" hide=true
flag "-P --profile" help="Set the profile (environment)" var=true hide=true global=true {
arg "<PROFILE>"
Expand All @@ -40,19 +34,25 @@ flag "-s --shell" hide=true {
flag "-t --tool" help="Tool(s) to run in addition to what is in mise.toml files e.g.: node@20 [email protected]" var=true hide=true {
arg "<TOOL@VERSION>"
}
flag "-q --quiet" help="Suppress non-error messages" global=true
flag "--raw" help="Read/write directly to stdin/stdout/stderr instead of by line" global=true
flag "--silent" help="Suppress all task output and mise non-error messages"
flag "--timings" help="Shows elapsed time after each task completes" hide=true {
long_help "Shows elapsed time after each task completes\n\nDefault to always show with `MISE_TASK_TIMINGS=1`"
}
flag "--no-timings" help="Hides elapsed time after each task completes" hide=true {
long_help "Hides elapsed time after each task completes\n\nDefault to always hide with `MISE_TASK_TIMINGS=0`"
}
flag "--trace" help="Sets log level to trace" hide=true global=true
flag "-v --verbose" help="Show extra output (use -vv for even more)" var=true global=true count=true
flag "-V --version" hide=true
flag "-y --yes" help="Answer yes to all confirmation prompts" global=true
flag "--debug" help="Sets log level to debug" hide=true global=true
flag "--log-level" hide=true global=true {
arg "<LEVEL>" {
choices "trace" "debug" "info" "warning" "error"
}
}
flag "-q --quiet" help="Suppress non-error messages" global=true
flag "--silent" help="Suppress all task output and mise non-error messages" global=true
flag "--trace" help="Sets log level to trace" hide=true global=true
flag "-v --verbose" help="Show extra output (use -vv for even more)" var=true global=true count=true
arg "[TASK]" help="Task to run" help_long="Task to run.\n\nShorthand for `mise task run <TASK>`."
arg "[TASK_ARGS]..." help="Task arguments" var=true hide=true
cmd "activate" help="Initializes mise in the current shell session" {
Expand Down Expand Up @@ -351,6 +351,17 @@ cmd "doctor" help="Check mise installation for possible problems" {
$ mise doctor
[WARN] plugin node is not installed
"
cmd "path" help="Print the current PATH entries mise is providing" {
after_long_help r"Examples:

Get the current PATH entries mise is providing
$ mise path
/home/user/.local/share/mise/installs/node/24.0.0/bin
/home/user/.local/share/mise/installs/rust/1.90.0/bin
/home/user/.local/share/mise/installs/python/3.10.0/bin
"
flag "-f --full" help="Print all entries including those not provided by mise"
}
}
cmd "en" help="[experimental] starts a new shell with the mise environment built from the current configuration" {
long_help r"[experimental] starts a new shell with the mise environment built from the current configuration
Expand Down
2 changes: 1 addition & 1 deletion registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ sqldef.backends = ["asdf:cometkim/asdf-sqldef"]
sqlite.backends = ["asdf:cLupus/asdf-sqlite"]
sshuttle.backends = ["asdf:xanmanning/asdf-sshuttle"]
stack.backends = ["aqua:commercialhaskell/stack", "asdf:sestrella/asdf-ghcup"]
stack.test = ["stack --version", "Version {{version}}"]
# stack.test = ["stack --version", "Version {{version}}"] # flaky
starboard.backends = ["aqua:aquasecurity/starboard", "asdf:zufardhiyaulhaq/asdf-starboard"]
starknet-foundry.backends = ["asdf:foundry-rs/asdf-starknet-foundry"]
starport.backends = ["asdf:nikever/asdf-starport"]
Expand Down
21 changes: 20 additions & 1 deletion src/cli/doctor.rs → src/cli/doctor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod path;

use crate::exit;

use crate::backend::backend_type::BackendType;
Expand Down Expand Up @@ -25,14 +27,31 @@ use strum::IntoEnumIterator;
#[derive(Debug, clap::Args)]
#[clap(visible_alias = "dr", verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
pub struct Doctor {
#[clap(subcommand)]
subcommand: Option<Commands>,
#[clap(skip)]
errors: Vec<String>,
#[clap(skip)]
warnings: Vec<String>,
}

#[derive(Debug, clap::Subcommand)]
pub enum Commands {
Path(path::Path),
}

impl Doctor {
pub fn run(mut self) -> eyre::Result<()> {
pub fn run(self) -> eyre::Result<()> {
if let Some(cmd) = self.subcommand {
match cmd {
Commands::Path(cmd) => cmd.run(),
}
} else {
self.doctor()
}
}

fn doctor(mut self) -> eyre::Result<()> {
info::inline_section("version", &*VERSION)?;
#[cfg(unix)]
info::inline_section("activated", yn(env::is_activated()))?;
Expand Down
41 changes: 41 additions & 0 deletions src/cli/doctor/path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::config::Config;
use crate::Result;
use std::env;

/// Print the current PATH entries mise is providing
#[derive(Debug, clap::Args)]
#[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
pub struct Path {
/// Print all entries including those not provided by mise
#[clap(long, short, verbatim_doc_comment)]
full: bool,
}

impl Path {
pub fn run(self) -> Result<()> {
let config = Config::get();
let ts = config.get_toolset()?;
let paths = if self.full {
let env = ts.env_with_path(&config)?;
let path = env.get("PATH").cloned().unwrap_or_default();
env::split_paths(&path).collect()
} else {
ts.list_final_paths()?
};
for path in paths {
println!("{}", path.display());
}
Ok(())
}
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>

Get the current PATH entries mise is providing
$ mise path
/home/user/.local/share/mise/installs/node/24.0.0/bin
/home/user/.local/share/mise/installs/rust/1.90.0/bin
/home/user/.local/share/mise/installs/python/3.10.0/bin
"#
);
46 changes: 27 additions & 19 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ pub struct Cli {
/// Dry run, don't actually do anything
#[clap(short = 'n', long, hide = true)]
pub dry_run: bool,
/// Sets log level to debug
#[clap(long, global = true, hide = true)]
pub debug: bool,
/// Set the environment for loading `mise.<ENV>.toml`
#[clap(short = 'E', long, global = true)]
pub env: Option<Vec<String>>,
Expand All @@ -107,8 +104,6 @@ pub struct Cli {
/// How many jobs to run in parallel [default: 8]
#[clap(long, short, global = true, env = "MISE_JOBS")]
pub jobs: Option<usize>,
#[clap(long, global = true, hide = true, value_name = "LEVEL", value_enum)]
pub log_level: Option<LevelFilter>,
#[clap(long, short, hide = true, overrides_with = "interleave")]
pub prefix: bool,
/// Set the profile (environment)
Expand All @@ -126,15 +121,9 @@ pub struct Cli {
env = "MISE_QUIET"
)]
pub tool: Vec<ToolArg>,
/// Suppress non-error messages
#[clap(short = 'q', long, global = true, overrides_with = "verbose")]
pub quiet: bool,
/// Read/write directly to stdin/stdout/stderr instead of by line
#[clap(long, global = true)]
pub raw: bool,
/// Suppress all task output and mise non-error messages
#[clap(long)]
pub silent: bool,
/// Shows elapsed time after each task completes
///
/// Default to always show with `MISE_TASK_TIMINGS=1`
Expand All @@ -146,17 +135,36 @@ pub struct Cli {
#[clap(long, alias = "no-timing", hide = true, verbatim_doc_comment)]
pub no_timings: bool,

/// Sets log level to trace
#[clap(long, global = true, hide = true)]
pub trace: bool,
/// Show extra output (use -vv for even more)
#[clap(short='v', long, global=true, overrides_with="quiet", action=ArgAction::Count)]
pub verbose: u8,
#[clap(long, short = 'V', hide = true)]
pub version: bool,
/// Answer yes to all confirmation prompts
#[clap(short = 'y', long, global = true)]
pub yes: bool,

#[clap(flatten)]
pub global_output_flags: CliGlobalOutputFlags,
}

#[derive(Debug, clap::Args)]
#[group(multiple = false)]
pub struct CliGlobalOutputFlags {
/// Sets log level to debug
#[clap(long, global = true, hide = true, overrides_with_all = &["quiet", "trace", "verbose", "silent", "log_level"])]
pub debug: bool,
#[clap(long, global = true, hide = true, value_name = "LEVEL", value_enum, overrides_with_all = &["quiet", "trace", "verbose", "silent", "debug"])]
pub log_level: Option<LevelFilter>,
/// Suppress non-error messages
#[clap(short = 'q', long, global = true, overrides_with_all = &["silent", "trace", "verbose", "debug", "log_level"])]
pub quiet: bool,
/// Suppress all task output and mise non-error messages
#[clap(long, global = true, overrides_with_all = &["quiet", "trace", "verbose", "debug", "log_level"])]
pub silent: bool,
/// Sets log level to trace
#[clap(long, global = true, hide = true, overrides_with_all = &["quiet", "silent", "verbose", "debug", "log_level"])]
pub trace: bool,
/// Show extra output (use -vv for even more)
#[clap(short='v', long, global=true, action=ArgAction::Count, overrides_with_all = &["quiet", "silent", "trace", "debug"])]
pub verbose: u8,
}

#[derive(Debug, Subcommand, strum::Display)]
Expand Down Expand Up @@ -349,8 +357,8 @@ impl Cli {
output: run::TaskOutput::Prefix,
prefix: self.prefix,
shell: self.shell,
quiet: self.quiet,
silent: self.silent,
quiet: self.global_output_flags.quiet,
silent: self.global_output_flags.silent,
raw: self.raw,
timings: self.timings,
tmpdir: Default::default(),
Expand Down
Loading
Loading