From b9ea0e4663857955ac0cf68c574ef5261ec678dc Mon Sep 17 00:00:00 2001 From: Jake Deichert Date: Fri, 19 Jul 2019 00:06:14 -0400 Subject: [PATCH] Change required arguments to use (round_brackets) instead of Fixes #15 Although it's quite obvious, I didn't even think about angle brackets causing a problem with renderers. I thought I saw them working within headings and not being parsed as html... Round brackets work nice. [square_brackets] will be used for optional args. --- README.md | 18 +++++++++--------- src/parser.rs | 12 ++++++------ test/maskfile.md | 16 ++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7a43abe..31229e9 100644 --- a/README.md +++ b/README.md @@ -74,12 +74,12 @@ mask test ### Positional arguments -These are defined beside the command name within ``. They are required arguments that must be supplied for the command to run. [Optional args][2] are coming soon. The argument name is injected into the script's scope as an environment variable. +These are defined beside the command name within `(round_brackets)`. They are required arguments that must be supplied for the command to run. [Optional args][2] are coming soon. The argument name is injected into the script's scope as an environment variable. **Example:** ```markdown -## test +## test (file) (test_case) > Run tests @@ -129,7 +129,7 @@ Nested command structures can easily be created since they are simply defined by > Commands related to starting, stopping, and restarting services -### services start +### services start (service_name) > Start a service. @@ -137,7 +137,7 @@ Nested command structures can easily be created since they are simply defined by echo "Starting service $service_name" ~~~ -### services stop +### services stop (service_name) > Stop a service. @@ -161,7 +161,7 @@ On top of shell/bash scripts, `mask` also supports using node, python, ruby and **Example:** ```markdown -## shell +## shell (name) > An example shell script @@ -173,7 +173,7 @@ echo "Hello, $name!" ~~~ -## node +## node (name) > An example node script @@ -185,7 +185,7 @@ console.log(`Hello, ${name}!`); ~~~ -## python +## python (name) > An example python script @@ -200,7 +200,7 @@ print("Hello, " + name + "!") ~~~ -## ruby +## ruby (name) > An example ruby script @@ -213,7 +213,7 @@ puts "Hello, #{name}!" ~~~ -## php +## php (name) > An example php script diff --git a/src/parser.rs b/src/parser.rs index eecfbe6..9400ccd 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -186,8 +186,8 @@ fn parse_command_name_and_required_args( // and level 2 can't be a subcommand so no need to split. let name = if heading_level > 2 { // Takes a subcommand name like this: - // "#### db flush postgres " - // and returns "postgres " as the actual name + // "#### db flush postgres (required_arg_name)" + // and returns "postgres (required_arg_name)" as the actual name text.clone() .split(" ") .collect::>() @@ -199,8 +199,8 @@ fn parse_command_name_and_required_args( text.clone() }; - // Find any required arguments. They look like this: - let name_and_args: Vec<&str> = name.split(|c| c == '<' || c == '>').collect(); + // Find any required arguments. They look like this: (required_arg_name) + let name_and_args: Vec<&str> = name.split(|c| c == '(' || c == ')').collect(); let (name, args) = name_and_args.split_at(1); let name = name.join(" ").trim().to_string(); let mut required_args: Vec = vec![]; @@ -225,7 +225,7 @@ const TEST_MASKFILE: &str = r#" This is an example maskfile for the tests below. -## serve +## serve (port) > Serve the app on the `port` @@ -233,7 +233,7 @@ This is an example maskfile for the tests below. echo "Serving on port $port" ~~~ -## node +## node (name) > An example node script diff --git a/test/maskfile.md b/test/maskfile.md index 0628ea5..e74c3d4 100644 --- a/test/maskfile.md +++ b/test/maskfile.md @@ -11,7 +11,7 @@ > Commands related to starting, stopping, and restarting services -### services start +### services start (service_name) > Start or restart a service. @@ -20,7 +20,7 @@ echo "Starting service $service_name" ~~~ -### services stop +### services stop (service_name) > Stop a service. @@ -65,7 +65,7 @@ echo "Flushed postgres" echo "Flushed redis" ~~~ -### db snapshot +### db snapshot (snapshot_name) > Take a snapshot of the database. @@ -73,7 +73,7 @@ echo "Flushed redis" echo "Saved db snapshot as '$snapshot_name'" ~~~ -### db restore +### db restore (snapshot_name) > Restore the database to a snapshot. @@ -111,7 +111,7 @@ server.listen(PORT, () => { -## input +## input (arg1) (arg2) > Example of how to accept user input and sleep @@ -152,7 +152,7 @@ fi -## python +## python (name) > An example python script @@ -168,7 +168,7 @@ print("Hello, " + name + "!") -## ruby +## ruby (name) > An example ruby script @@ -182,7 +182,7 @@ puts "Hello, #{name}!" -## php +## php (name) > An example php script