Skip to content

Commit

Permalink
fix: Improper passing of subcommands as project
Browse files Browse the repository at this point in the history
Contributions by @coreyja to address a problem where subcommands that are called without a project name result in using the subcommand itself as a project name.
Instead check to ensure when using the default execution without a subcommand a project with the name of a subcommand isn't called accidentally. Do allow projects with the same name as subcommands but only while explicitly using the `load` subcommand.

Thanks @coreyja!

Closes #45, closes #46
  • Loading branch information
brianp committed Dec 29, 2019
1 parent 7bec9bd commit 655b6fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions common/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use serde::Deserialize;
/// `flag_debug` run inline print statements for debugging
/// `arg_project` the project file to read
/// `cmd_edit` if `true` run edit command
/// `cmd_load` if `true` run load command (This is also the default command)
/// `cmd_new` if `true` run new command
/// `cmd_snapshot` if `true` run snapshot command
/// `cmd_load` if `true` run load command (This is also the default command)
///
#[derive(Debug, Deserialize)]
pub struct Args {
Expand All @@ -26,9 +26,9 @@ pub struct Args {
pub flag_v: bool,
pub arg_project: String,
pub cmd_edit: bool,
pub cmd_load: bool,
pub cmd_new: bool,
pub cmd_snapshot: bool,
pub cmd_load: bool,
}

impl Default for Args {
Expand All @@ -38,9 +38,9 @@ impl Default for Args {
Args {
arg_project: name,
cmd_edit: false,
cmd_load: false,
cmd_new: true,
cmd_snapshot: false,
cmd_load: false,
flag_d: true,
flag_debug: false,
flag_f: false,
Expand Down
20 changes: 10 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ static DISALLOWED_SHORTHAND_PROJECT_NAMES: [&str; 4] = ["new", "edit", "load", "

static USAGE: &str = "
Usage:
muxed [options] <project>
muxed [flags] [options] <project>
muxed edit [options] <project>
muxed new [options] <project>
muxed snapshot [options] <project>
muxed load [options] <project>
muxed load [flags] [options] <project>
muxed new [flags] [options] <project>
muxed snapshot [flags] [options] <project>
muxed (-h | --help)
muxed (-v | --version)
Expand All @@ -52,9 +52,9 @@ Args:
Subcommands:
edit <project> Edit an existing project file
load <project> Load the specified project, this is the default command
new <project> To create a new project file
snapshot -t <session> <project> Capture a running session and create a config file for it
load Load the specified project, this is the default command
";

/// The main execution method.
Expand Down Expand Up @@ -89,14 +89,14 @@ pub fn main() {
exit(0);
};

if args.cmd_new {
try_or_err!(new::exec(args));
} else if args.cmd_edit {
if args.cmd_edit {
try_or_err!(edit::exec(args));
} else if args.cmd_snapshot {
try_or_err!(snapshot::exec(args));
} else if args.cmd_load {
try_or_err!(load::exec(args));
} else if args.cmd_new {
try_or_err!(new::exec(args));
} else if args.cmd_snapshot {
try_or_err!(snapshot::exec(args));
} else {
if DISALLOWED_SHORTHAND_PROJECT_NAMES.contains(&args.arg_project.as_ref()) {
println!(
Expand Down

0 comments on commit 655b6fb

Please sign in to comment.