Skip to content
Open
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
8 changes: 6 additions & 2 deletions crates/muvm/src/bin/muvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ fn pulse_path_from_pulse_server() -> Result<CString> {
fn main() -> Result<ExitCode> {
env_logger::init();

let options = options().fallback_to_usage().run();

if getuid().as_raw() == 0 || geteuid().as_raw() == 0 {
println!("Running as root is not supported as it may break your system");
return Err(anyhow!("real user ID or effective user ID is 0"));
}

let options = options().fallback_to_usage().run();
let command = options
.command
.ok_or_else(|| anyhow!("expected `COMMAND`, pass `--help` for usage information"))?;
let config = Configuration::parse_config_file()?;

let mut init_commands = options.init_commands;
Expand All @@ -117,7 +121,7 @@ fn main() -> Result<ExitCode> {
}

let (_lock_file, command, command_args, env) = match launch_or_lock(
options.command,
command,
options.command_args,
options.env,
options.interactive,
Expand Down
9 changes: 6 additions & 3 deletions crates/muvm/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct Options {
pub emulator: Option<Emulator>,
pub init_commands: Vec<PathBuf>,
pub user_init_commands: Vec<PathBuf>,
pub command: PathBuf,
pub command: Option<PathBuf>,
pub command_args: Vec<String>,
}

Expand Down Expand Up @@ -189,9 +189,11 @@ pub fn options() -> OptionParser<Options> {
)
.argument("COMMAND")
.many();
let command = positional("COMMAND").help("the command you want to execute in the vm");
let command = positional("COMMAND")
.help("the command you want to execute in the vm")
.optional();
let command_args = any::<String, _, _>("COMMAND_ARGS", |arg| {
(!["--help", "-h"].contains(&&*arg)).then_some(arg)
(!["--help", "-h", "--version", "-V"].contains(&&*arg)).then_some(arg)
})
.help("arguments of COMMAND")
.many();
Expand All @@ -218,6 +220,7 @@ pub fn options() -> OptionParser<Options> {
command_args,
})
.to_options()
.version(env!("CARGO_PKG_VERSION"))
}

#[cfg(test)]
Expand Down