-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --maskfile-introspect flag to print out the maskfile command stru…
…cture as json (#85) * Add --maskfile-introspect flag to print out command structure in json format * Add test for --maskfile-introspect
- Loading branch information
1 parent
cbc1c72
commit 9cb6007
Showing
4 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
mod common; | ||
use assert_cmd::prelude::*; | ||
use predicates::str::contains; | ||
use serde_json::json; | ||
|
||
#[test] | ||
fn outputs_the_maskfile_structure_as_json() { | ||
let (_temp, maskfile_path) = common::maskfile( | ||
r#" | ||
# Document Title | ||
## somecommand | ||
> The command description | ||
~~~bash | ||
echo something | ||
~~~ | ||
"#, | ||
); | ||
|
||
let verbose_flag = json!({ | ||
"name": "verbose", | ||
"description": "Sets the level of verbosity", | ||
"short": "v", | ||
"long": "verbose", | ||
"multiple": false, | ||
"takes_value": false, | ||
"required": false, | ||
"validate_as_number": false, | ||
}); | ||
|
||
let expected_json = json!({ | ||
"title": "Document Title", | ||
"description": "", | ||
"commands": [ | ||
{ | ||
"level": 2, | ||
"name": "somecommand", | ||
"description": "The command description", | ||
"script": { | ||
"executor": "bash", | ||
"source": "echo something\n", | ||
}, | ||
"subcommands": [], | ||
"required_args": [], | ||
"named_flags": [verbose_flag], | ||
} | ||
] | ||
}); | ||
|
||
common::run_mask(&maskfile_path) | ||
.arg("--maskfile-introspect") | ||
.assert() | ||
.code(0) | ||
.stdout(contains( | ||
serde_json::to_string_pretty(&expected_json).unwrap(), | ||
)) | ||
.success(); | ||
} |