-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #550 from DannyBen/refactor/private-commands
Allow ad-hoc revealing of private commands, flags, and environment variables
- Loading branch information
Showing
34 changed files
with
571 additions
and
40 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*.gem | ||
/.yardoc | ||
/coverage | ||
/spec/coverage | ||
/dev | ||
/doc | ||
/Gemfile.lock | ||
|
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 @@ | ||
cli |
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,181 @@ | ||
# Private Reveal Example | ||
|
||
Demonstrates how to allow users to reveal any private commands, flags and | ||
environment variables. | ||
|
||
This example was generated with: | ||
|
||
```bash | ||
$ bashly init | ||
$ bashly add settings | ||
# ... now edit settings.yml to match the example ... | ||
# ... now edit src/bashly.yml to match the example ... | ||
$ bashly generate | ||
``` | ||
|
||
<!-- include: settings.yml --> | ||
|
||
----- | ||
|
||
## `bashly.yml` | ||
|
||
````yaml | ||
name: cli | ||
help: Sample application | ||
version: 0.1.0 | ||
|
||
# All elements with `private: true` in this configuration will be hidden | ||
# unless the environment variable SHOW_PELASE is set (as defined | ||
# in ../settings.yml) | ||
|
||
environment_variables: | ||
- name: secret | ||
help: Set secret key | ||
private: true | ||
|
||
flags: | ||
- long: --debug | ||
help: Enable debug mode | ||
private: true | ||
|
||
commands: | ||
- name: admin | ||
help: Admin operations | ||
expose: true | ||
|
||
commands: | ||
- name: list | ||
help: List connected devices | ||
- name: reboot | ||
help: Reboot | ||
private: true | ||
```` | ||
|
||
## `settings.yml` | ||
|
||
````yaml | ||
# When using private commands, flags, or environment variables, you may set | ||
# this option to a name of an environment variable that, if set, will reveal | ||
# all the private elements in the usage texts, as if they were public. | ||
private_reveal_key: SHOW_PLEASE | ||
```` | ||
|
||
|
||
## Output | ||
|
||
### `$ ./cli` | ||
|
||
````shell | ||
cli - Sample application | ||
|
||
Usage: | ||
cli [OPTIONS] COMMAND | ||
cli [COMMAND] --help | -h | ||
cli --version | -v | ||
|
||
Commands: | ||
admin Admin operations | ||
|
||
|
||
|
||
```` | ||
|
||
### `$ ./cli -h` | ||
|
||
````shell | ||
cli - Sample application | ||
|
||
Usage: | ||
cli [OPTIONS] COMMAND | ||
cli [COMMAND] --help | -h | ||
cli --version | -v | ||
|
||
Commands: | ||
admin Admin operations | ||
admin list List connected devices | ||
|
||
Global Options: | ||
--help, -h | ||
Show this help | ||
|
||
--version, -v | ||
Show version number | ||
|
||
|
||
|
||
```` | ||
|
||
### `$ ./cli admin -h` | ||
|
||
````shell | ||
cli admin - Admin operations | ||
|
||
Usage: | ||
cli admin COMMAND | ||
cli admin [COMMAND] --help | -h | ||
|
||
Commands: | ||
list List connected devices | ||
|
||
Options: | ||
--help, -h | ||
Show this help | ||
|
||
|
||
|
||
```` | ||
|
||
### `$ export SHOW_PLEASE=1` | ||
|
||
````shell | ||
|
||
|
||
```` | ||
|
||
### `$ ./cli -h` | ||
|
||
````shell | ||
cli - Sample application | ||
|
||
Usage: | ||
cli [OPTIONS] COMMAND | ||
cli [COMMAND] --help | -h | ||
cli --version | -v | ||
|
||
Commands: | ||
admin Admin operations | ||
admin list List connected devices | ||
|
||
Global Options: | ||
--help, -h | ||
Show this help | ||
|
||
--version, -v | ||
Show version number | ||
|
||
|
||
|
||
```` | ||
|
||
### `$ ./cli admin -h` | ||
|
||
````shell | ||
cli admin - Admin operations | ||
|
||
Usage: | ||
cli admin COMMAND | ||
cli admin [COMMAND] --help | -h | ||
|
||
Commands: | ||
list List connected devices | ||
|
||
Options: | ||
--help, -h | ||
Show this help | ||
|
||
|
||
|
||
```` | ||
|
||
|
||
|
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,4 @@ | ||
# When using private commands, flags, or environment variables, you may set | ||
# this option to a name of an environment variable that, if set, will reveal | ||
# all the private elements in the usage texts, as if they were public. | ||
private_reveal_key: SHOW_PLEASE |
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,4 @@ | ||
echo "# this file is located in 'src/admin_list_command.sh'" | ||
echo "# code for 'cli admin list' goes here" | ||
echo "# you can edit it freely and regenerate (it will not be overwritten)" | ||
inspect_args |
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,4 @@ | ||
echo "# this file is located in 'src/admin_reboot_command.sh'" | ||
echo "# code for 'cli admin reboot' goes here" | ||
echo "# you can edit it freely and regenerate (it will not be overwritten)" | ||
inspect_args |
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,29 @@ | ||
name: cli | ||
help: Sample application | ||
version: 0.1.0 | ||
|
||
# All elements with `private: true` in this configuration will be hidden | ||
# unless the environment variable SHOW_PELASE is set (as defined | ||
# in ../settings.yml) | ||
|
||
environment_variables: | ||
- name: secret | ||
help: Set secret key | ||
private: true | ||
|
||
flags: | ||
- long: --debug | ||
help: Enable debug mode | ||
private: true | ||
|
||
commands: | ||
- name: admin | ||
help: Admin operations | ||
expose: true | ||
|
||
commands: | ||
- name: list | ||
help: List connected devices | ||
- name: reboot | ||
help: Reboot | ||
private: true |
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,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -f ./src/*.sh | ||
|
||
set -x | ||
|
||
bashly generate | ||
|
||
### Try Me ### | ||
|
||
./cli | ||
./cli -h | ||
./cli admin -h | ||
|
||
export SHOW_PLEASE=1 | ||
|
||
./cli -h | ||
./cli admin -h |
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
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
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,19 @@ | ||
module Bashly | ||
module Script | ||
module Introspection | ||
module Visibility | ||
# Returns :public, :private, or :semi_private based on the `private` | ||
# option of the host, in conjunction with `Settings.private_reveal_key`. | ||
def visibility | ||
if !options['private'] | ||
:public | ||
elsif Settings.private_reveal_key | ||
:semi_private | ||
else | ||
:private | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.