From 655b6fba9ef9dd3e5257f150f174e740c26cc702 Mon Sep 17 00:00:00 2001 From: Brian Pearce Date: Sun, 29 Dec 2019 21:43:16 +0100 Subject: [PATCH] fix: Improper passing of subcommands as project 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 --- common/src/args.rs | 6 +++--- src/main.rs | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common/src/args.rs b/common/src/args.rs index 9d781de..2ca4fde 100644 --- a/common/src/args.rs +++ b/common/src/args.rs @@ -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 { @@ -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 { @@ -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, diff --git a/src/main.rs b/src/main.rs index 21e81ec..6fbef62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,11 +28,11 @@ static DISALLOWED_SHORTHAND_PROJECT_NAMES: [&str; 4] = ["new", "edit", "load", " static USAGE: &str = " Usage: - muxed [options] + muxed [flags] [options] muxed edit [options] - muxed new [options] - muxed snapshot [options] - muxed load [options] + muxed load [flags] [options] + muxed new [flags] [options] + muxed snapshot [flags] [options] muxed (-h | --help) muxed (-v | --version) @@ -52,9 +52,9 @@ Args: Subcommands: edit Edit an existing project file + load Load the specified project, this is the default command new To create a new project file snapshot -t 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. @@ -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!(