rbcli 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +50 -6
- data/exe/rbcli +81 -32
- data/lib/rbcli/configuration/config.rb +6 -6
- data/lib/rbcli/configuration/configurate.rb +1 -1
- data/lib/rbcli/engine/load_project.rb +19 -0
- data/lib/rbcli/engine/parser.rb +2 -2
- data/lib/rbcli/logging/logging.rb +7 -4
- data/lib/rbcli/stateful_systems/state_storage.rb +4 -0
- data/lib/rbcli/version.rb +1 -1
- data/lib/rbcli-tool/erb_renderer.rb +43 -0
- data/lib/rbcli-tool/mdless_fix.rb +386 -0
- data/lib/rbcli-tool/project.rb +87 -0
- data/lib/rbcli-tool.rb +16 -0
- data/lib/rbcli.rb +11 -10
- data/rbcli.gemspec +1 -0
- data/skeletons/micro/executable +123 -0
- data/skeletons/mini/executable +241 -0
- data/skeletons/project/.gitignore +11 -0
- data/skeletons/project/.rbcli +0 -0
- data/skeletons/project/.rspec +3 -0
- data/skeletons/project/CODE_OF_CONDUCT.md +74 -0
- data/skeletons/project/Gemfile +6 -0
- data/skeletons/project/README.md +31 -0
- data/skeletons/project/Rakefile +6 -0
- data/skeletons/project/application/commands/command.rb +31 -0
- data/skeletons/project/application/commands/scripts/script.sh +23 -0
- data/skeletons/project/application/options.rb +30 -0
- data/skeletons/project/config/autoupdate.rb +32 -0
- data/skeletons/project/config/logging.rb +19 -0
- data/skeletons/project/config/storage.rb +34 -0
- data/skeletons/project/config/userspace.rb +28 -0
- data/skeletons/project/config/version.rb +3 -0
- data/skeletons/project/default_user_configs/user_defaults.yml +6 -0
- data/skeletons/project/exe/executable +54 -0
- data/skeletons/project/hooks/default_action.rb +16 -0
- data/skeletons/project/hooks/first_run.rb +16 -0
- data/skeletons/project/hooks/post_execution.rb +14 -0
- data/skeletons/project/hooks/pre_execution.rb +14 -0
- data/skeletons/project/spec/spec_helper.rb +14 -0
- data/skeletons/project/spec/untitled_spec.rb +9 -0
- data/skeletons/project/untitled.gemspec +40 -0
- metadata +47 -2
@@ -0,0 +1,241 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#########################################################
|
4
|
+
### <%= @vars[:cmdname] %>
|
5
|
+
#######
|
6
|
+
## This is the main executable for <%= @vars[:cmdname] %>.
|
7
|
+
## It's job is to load and execute the application.
|
8
|
+
#########################################################
|
9
|
+
|
10
|
+
require 'rbcli'
|
11
|
+
|
12
|
+
#########################
|
13
|
+
## Configuration Block ##
|
14
|
+
#########################
|
15
|
+
# This block is where rbcli is configured.
|
16
|
+
# Any options marked as Optional can be commented out.
|
17
|
+
# Options marked as Multiple can be declared multiple times.
|
18
|
+
#########################
|
19
|
+
|
20
|
+
Rbcli::Configurate.me do
|
21
|
+
|
22
|
+
####
|
23
|
+
# GENERAL
|
24
|
+
###
|
25
|
+
# These parameters are for genreal information about your application.
|
26
|
+
###
|
27
|
+
|
28
|
+
## Script Name -- (Required) -- This line identifies the tool's executable on the command line.
|
29
|
+
# To change it, rename this file to the command you want and this will pick up that name automatically.
|
30
|
+
# You can change it manually if needed, but this should work for most cases.
|
31
|
+
scriptname __FILE__.split('/')[-1]
|
32
|
+
|
33
|
+
## Version Number -- (Required)
|
34
|
+
version '0.1.0'
|
35
|
+
|
36
|
+
## Description -- (Requierd) -- A description that will appear when the user looks at the help with -h. This can be as long as needed.
|
37
|
+
description %q{<%= @vars[:description] %>}
|
38
|
+
|
39
|
+
|
40
|
+
####
|
41
|
+
# LOGGING
|
42
|
+
###
|
43
|
+
# These parameters set the default logging parameters for your applicaiton. Note that a user
|
44
|
+
# can override these settings by modifying their local configuration.
|
45
|
+
# If either option is set to nil, or they are not provided, logging is disabled.
|
46
|
+
###
|
47
|
+
|
48
|
+
## Log Target -- (Optional) -- Set the target for logs.
|
49
|
+
# Valid values are nil, 'STDOUT', 'STDERR', or a file path (as strings).
|
50
|
+
# Default is disabled (nil).
|
51
|
+
log_target nil
|
52
|
+
|
53
|
+
## Log Level -- (Optional) -- Set the default log_level for users.
|
54
|
+
# Valid values are nil, 0-5, or DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN.
|
55
|
+
# Default is disabled (nil).
|
56
|
+
log_level nil
|
57
|
+
|
58
|
+
|
59
|
+
####
|
60
|
+
# USER CONFIGURATION MANAGEMENT
|
61
|
+
###
|
62
|
+
# RBCli allows you to create a configuration file that your users can modify.
|
63
|
+
# Users will be able to generate their own file by running your tool with the `-g` option.
|
64
|
+
# To disable this feature, comment out the `config_userfile` line below.
|
65
|
+
###
|
66
|
+
|
67
|
+
## Config Userfile -- (Optional) -- Set location of user's config file.
|
68
|
+
#
|
69
|
+
# config_userfile <path>, merge_defaults: <optional: (true|false), default: true>, required: <optional: (true|false, default: false)
|
70
|
+
#
|
71
|
+
# If merge_defaults=true, user settings override default settings.
|
72
|
+
# If false, defaults set here are not loaded at all, and the user is required to set them.
|
73
|
+
# If required=true, application will not run if file does not exist.
|
74
|
+
config_userfile '~/.<%= @vars[:cmdname] %>', merge_defaults: true, required: false
|
75
|
+
|
76
|
+
## Config Defaults -- (Optional, Multiple) -- Load a YAML file as part of the default config.
|
77
|
+
# This can be called multiple times, and the YAML files will be merged. User config is generated from these files.
|
78
|
+
# TODO: This line is not needed when using RBCli in standard mode. YAML files go in the `user_configs` directory instead.
|
79
|
+
#config_defaults 'defaults.yml'
|
80
|
+
|
81
|
+
## Config Default -- (Optional, Multiple) -- Specify an individual configuration parameter and set a default value.
|
82
|
+
# These will be included in generated user config.
|
83
|
+
config_default :myopt, description: 'Testing this', default: true
|
84
|
+
|
85
|
+
|
86
|
+
####
|
87
|
+
# AUTOUPDATE
|
88
|
+
###
|
89
|
+
# RBCli can notify users when you have an update to your application.
|
90
|
+
# This requires your application to be published either on Rubygems.org, Github, or Github Enterprise.
|
91
|
+
# Note that only one can be enabled at a time.
|
92
|
+
# For more details on each integration, see below.
|
93
|
+
###
|
94
|
+
|
95
|
+
## Autoupdate, Github -- (Optional) -- Check for updates to this application at a GitHub repo.
|
96
|
+
# The repo should use version number tags in accordance to Github's best practices: https://help.github.com/articles/creating-releases/
|
97
|
+
#
|
98
|
+
# Note that the `access_token` can be overridden by the user via their configuration file, so it can be left as `nil`,
|
99
|
+
# which will require your users to enter their github tokens to use this feature.
|
100
|
+
# For instructions on generating a new access token, see: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
|
101
|
+
# The token is not needed if using a public repo.
|
102
|
+
#
|
103
|
+
# The `enterprise_hostname` setting allows you to point RBCli at a local GitHub Enterprise server.
|
104
|
+
#
|
105
|
+
# Setting `force_update: true` will halt execution if an update is available, forcing the user to update.
|
106
|
+
#
|
107
|
+
#autoupdate github_repo: '<your_user>/<your_repo>', access_token: nil, enterprise_hostname: nil, force_update: false
|
108
|
+
|
109
|
+
## Autoupdate, Rubygems.org -- (Optional) -- Check for updates to this application on Rubygems.org
|
110
|
+
#autoupdate gem: '<your_gem>', force_update: false
|
111
|
+
|
112
|
+
####
|
113
|
+
# Command Line Options
|
114
|
+
###
|
115
|
+
# Here you can set global options for users on the command line.
|
116
|
+
# RBCli supports commands with syntax as follows:
|
117
|
+
# toolname [options] command [parameters] [lineitem]
|
118
|
+
#
|
119
|
+
# Here you are defining the [options]. The parameters and lineitms (subcommands) are
|
120
|
+
# defined under their command blocks.
|
121
|
+
#
|
122
|
+
# The following types are supported: `:string`, `:boolean` or `:flag`, `:integer`, and `:float`
|
123
|
+
#
|
124
|
+
# If a default value is not set, it will default to `nil`.
|
125
|
+
#
|
126
|
+
# To specify multiple options, simply copy the line and modify as desired.
|
127
|
+
#
|
128
|
+
# Once parsed, option values will be placed in a hash where they can be accessed via their names as shown above where
|
129
|
+
# they are made available to your hooks and commands.
|
130
|
+
###
|
131
|
+
|
132
|
+
## Option -- (Optional, Multiple) -- Add a global CLI Option
|
133
|
+
option :name, 'Give me your name', type: :string, default: 'Foo', required: false, permitted: ['Jack', 'Jill']
|
134
|
+
|
135
|
+
|
136
|
+
####
|
137
|
+
# HOOKS
|
138
|
+
###
|
139
|
+
# Here you can set hooks that will be run at specified points in the execution chain.
|
140
|
+
# Global CLI options are made available to many of the hooks, but command parameters and lineitems are not.
|
141
|
+
###
|
142
|
+
|
143
|
+
## Default Action -- (Optional) -- The default code to execute when no subcommand is given.
|
144
|
+
# If not present, the help is shown (same as -h)
|
145
|
+
default_action do |opts|
|
146
|
+
puts "Hello, #{opts[:name]}."
|
147
|
+
puts "To see the help, use -h"
|
148
|
+
end
|
149
|
+
|
150
|
+
## Pre-Execution Hook -- (Optional) -- Allows providing a block of code that runs _before_ all commands
|
151
|
+
pre_hook do |opts|
|
152
|
+
puts 'This is a pre-command hook. It executes before the command.'
|
153
|
+
end
|
154
|
+
|
155
|
+
## Post-Execution Hook -- (Optional) -- Allows providing a block of code that runs _after_ all commands
|
156
|
+
post_hook do |opts|
|
157
|
+
puts 'This is a post-command hook. It executes after the command.'
|
158
|
+
end
|
159
|
+
|
160
|
+
## First-Run Hook -- (Optional) -- Allows providing a block of code that executes the first time that the application is run on a given system.
|
161
|
+
# If `halt_after_running` is set to `true` then parsing will not continue after this code is executed. All subsequent runs will not execute this code.
|
162
|
+
# This feature is dependent on the Local State Storage system, and will not run without it.
|
163
|
+
first_run halt_after_running: false do
|
164
|
+
puts "This is the first time the mytool command is run! Don't forget to generate a config file with the `-g` option before continuing."
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
###############################
|
169
|
+
## State Configuration Block ##
|
170
|
+
###############################
|
171
|
+
# The state-related componets
|
172
|
+
# are configured here.
|
173
|
+
###############################
|
174
|
+
Rbcli::Configurate.storage do
|
175
|
+
###
|
176
|
+
# Local State Storage
|
177
|
+
###
|
178
|
+
# Local state storage creates a hash that is automatically saved to a file locally for state persistance.
|
179
|
+
# It is accessible to all commands at: Rbcli.localstate[:yourkeyhere]
|
180
|
+
#
|
181
|
+
# Note that every update to the top level of this hash will trigger a save, and updating nested hashes will not.
|
182
|
+
# If you need to update nested hashes, you can trigger a save manually by calling `Rbcli.localstate.commit`.
|
183
|
+
# Please see the documentation for full usage details.
|
184
|
+
###
|
185
|
+
|
186
|
+
#local_state '/var/mytool/localstate', force_creation: true, halt_on_error: true # (Optional) Creates a hash that is automatically saved to a file locally for state persistance. It is accessible to all commands at Rbcli.localstate[:yourkeyhere]
|
187
|
+
|
188
|
+
|
189
|
+
###
|
190
|
+
# Remote State Storage
|
191
|
+
###
|
192
|
+
# Remote state storage creates a hash that is automatically saved to a remote database for state persistence.
|
193
|
+
# This state can be made unique to each user, or can be shared across different users of the tool.
|
194
|
+
#
|
195
|
+
# When sharing, locking should be set to `true`. Note that RBCli uses lazy-loaded, meaning the lock will
|
196
|
+
# only be acquired when absolutely needed. This behavior can be overridden manually if desired.
|
197
|
+
# For full usage details, see the documentation.
|
198
|
+
###
|
199
|
+
|
200
|
+
#remote_state_dynamodb table_name: 'mytable', region: 'us-east-1', force_creation: true, halt_on_error: true, locking: :auto # (Optional) Creates a hash that is automatically saved to a DynamoDB table. It is recommended to keep halt_on_error=true when using a shared state. Locking can be one of (:manual :auto :none) -- see the README for details
|
201
|
+
end
|
202
|
+
|
203
|
+
#########################
|
204
|
+
## Command Declaration ##
|
205
|
+
#########################
|
206
|
+
# With rbcli, commands are declared by subclassing
|
207
|
+
# from Rbcli::Command. The name of the class will be
|
208
|
+
# the command that is available to the user.
|
209
|
+
#########################
|
210
|
+
class Test < Rbcli::Command # Declare a new command by subclassing Rbcli::Command
|
211
|
+
description 'This is a short description.' # (Required) Short description for the global help
|
212
|
+
usage 'This is some really long usage text description!' # (Required) Long description for the command-specific help
|
213
|
+
parameter :force, 'Force testing', type: :boolean, default: false, required: false # (Optional, Multiple) Add a command-specific CLI parameter. Can be called multiple times
|
214
|
+
|
215
|
+
config_defaults 'defaults.yml' # (Optional, Multiple) Load a YAML file as part of the default config. This can be called multiple times, and the YAML files will be merged. User config is generated from these
|
216
|
+
config_default :myopt2, description: 'Testing this again', default: true # (Optional, Multiple) Specify an individual configuration parameter and set a default value. These will also be included in generated user config
|
217
|
+
|
218
|
+
extern path: 'env | grep "^__PARAMS\|^__ARGS\|^__GLOBAL\|^__CONFIG"', envvars: {MYVAR: 'some_value'} # (Required unless `action` defined) Runs a given application, with optional environment variables, when the user runs the command.
|
219
|
+
extern envvars: {MY_OTHER_VAR: 'another_value'} do |params, args, global_opts, config| # Alternate usage. Supplying a block instead of a path allows us to modify the command based on the arguments and configuration supplied by the user.
|
220
|
+
"echo #{params[:force].to_s}__YESSS!!!"
|
221
|
+
end
|
222
|
+
|
223
|
+
action do |params, args, global_opts, config| # (Required unless `extern` defined) Block to execute if the command is called.
|
224
|
+
Rbcli::log.info { 'These logs can go to STDERR, STDOUT, or a file' } # Example log. Interface is identical to Ruby's logger
|
225
|
+
puts "\nArgs:\n#{args}" # Arguments that came after the command on the CLI (i.e.: `mytool test bar baz` will yield args=['bar', 'baz'])
|
226
|
+
puts "Params:\n#{params}" # Parameters, as described through the option statements above
|
227
|
+
puts "Global opts:\n#{global_opts}" # Global Parameters, as descirbed in the Configurate section
|
228
|
+
puts "Config:\n#{config}" # Config file values
|
229
|
+
puts "LocalState:\n#{Rbcli.local_state}" # Local persistent state storage (when available) -- if unsure use Rbcli.local_state.nil?
|
230
|
+
puts "RemoteState:\n#{Rbcli.remote_state}" # Remote persistent state storage (when available) -- if unsure use Rbcli.remote_state.nil?
|
231
|
+
puts "\nDone!!!"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
#####################
|
236
|
+
## Parse Statement ##
|
237
|
+
#####################
|
238
|
+
# When this statement is called, the CLI will be
|
239
|
+
# parsed and code executed.
|
240
|
+
#####################
|
241
|
+
Rbcli.parse # Parse CLI and execute
|
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at akhoury@live.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# <%= @vars[:cmdname] %>
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem.
|
4
|
+
|
5
|
+
You'll find your gem's Command Line entrypoint under the file `exe/<%= @vars[:cmdname] %>`, although you shouldn't need to edit this file. Instead, follow these steps to get up and running quickly:
|
6
|
+
|
7
|
+
* Review the configuration under the `config` directory
|
8
|
+
* Modify global CLI options under the `application/options.rb` file
|
9
|
+
* Generate a new command by running `rbcli generate -t command -n <name>`
|
10
|
+
* Modify the command's code under `application/commands/<name>.rb`
|
11
|
+
* Repeat the previous two steps until complete!
|
12
|
+
|
13
|
+
For more details, including advanced usage, please see the [RBCli documentation](https://github.com/akhoury6/rbcli).
|
14
|
+
|
15
|
+
TODO: Delete the text above and write your README!
|
16
|
+
|
17
|
+
## About
|
18
|
+
|
19
|
+
<%= @vars[:description] %>
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `config/version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/untitled. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
28
|
+
|
29
|
+
## Code of Conduct
|
30
|
+
|
31
|
+
Everyone interacting in the Untitled project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/untitled/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#########################
|
2
|
+
## Command Declaration ##
|
3
|
+
#########################
|
4
|
+
# With rbcli, commands are declared by subclassing
|
5
|
+
# from Rbcli::Command. The name of the class will be
|
6
|
+
# the command that is available to the user.
|
7
|
+
#########################
|
8
|
+
class Test < Rbcli::Command # Declare a new command by subclassing Rbcli::Command
|
9
|
+
description 'This is a short description.' # (Required) Short description for the global help
|
10
|
+
usage 'This is some really long usage text description!' # (Required) Long description for the command-specific help
|
11
|
+
parameter :force, 'Force testing', type: :boolean, default: false, required: false # (Optional, Multiple) Add a command-specific CLI parameter. Can be called multiple times
|
12
|
+
|
13
|
+
config_defaults 'defaults.yml' # (Optional, Multiple) Load a YAML file as part of the default config. This can be called multiple times, and the YAML files will be merged. User config is generated from these
|
14
|
+
config_default :myopt2, description: 'Testing this again', default: true # (Optional, Multiple) Specify an individual configuration parameter and set a default value. These will also be included in generated user config
|
15
|
+
|
16
|
+
extern path: 'env | grep "^__PARAMS\|^__ARGS\|^__GLOBAL\|^__CONFIG"', envvars: {MYVAR: 'some_value'} # (Required unless `action` defined) Runs a given application, with optional environment variables, when the user runs the command.
|
17
|
+
extern envvars: {MY_OTHER_VAR: 'another_value'} do |params, args, global_opts, config| # Alternate usage. Supplying a block instead of a path allows us to modify the command based on the arguments and configuration supplied by the user.
|
18
|
+
"echo #{params[:force].to_s}__YESSS!!!"
|
19
|
+
end
|
20
|
+
|
21
|
+
action do |params, args, global_opts, config| # (Required unless `extern` defined) Block to execute if the command is called.
|
22
|
+
Rbcli::log.info { 'These logs can go to STDERR, STDOUT, or a file' } # Example log. Interface is identical to Ruby's logger
|
23
|
+
puts "\nArgs:\n#{args}" # Arguments that came after the command on the CLI (i.e.: `mytool test bar baz` will yield args=['bar', 'baz'])
|
24
|
+
puts "Params:\n#{params}" # Parameters, as described through the option statements above
|
25
|
+
puts "Global opts:\n#{global_opts}" # Global Parameters, as descirbed in the Configurate section
|
26
|
+
puts "Config:\n#{config}" # Config file values
|
27
|
+
puts "LocalState:\n#{Rbcli.local_state}" # Local persistent state storage (when available) -- if unsure use Rbcli.local_state.nil?
|
28
|
+
puts "RemoteState:\n#{Rbcli.remote_state}" # Remote persistent state storage (when available) -- if unsure use Rbcli.remote_state.nil?
|
29
|
+
puts "\nDone!!!"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
###
|
4
|
+
# This is the RBCli script for the command {{**CMDNAME**}}
|
5
|
+
###
|
6
|
+
#
|
7
|
+
# You can find RBCli's params, args, global_opts, and config through environment
|
8
|
+
# variables. They are passed in the formats:
|
9
|
+
#
|
10
|
+
# __PARAMS_<param_name>
|
11
|
+
# __ARGS_<arg_name>
|
12
|
+
# __GOBAL <global_opt_name>
|
13
|
+
# __CONFIG <config_name>
|
14
|
+
#
|
15
|
+
# If any of the options given had nested values in your RBCli application they
|
16
|
+
# will be passed as JSON. You can parse them using jq ( https://stedolan.github.io/jq/ )
|
17
|
+
#
|
18
|
+
# If you specified any environment variables to be set manually, they will be found unmodified.
|
19
|
+
#
|
20
|
+
###
|
21
|
+
#
|
22
|
+
|
23
|
+
env | grep "^__PARAMS\|^__ARGS\|^__GLOBAL\|^__CONFIG"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Rbcli::Configurate.me do
|
2
|
+
####
|
3
|
+
# Command Line Options
|
4
|
+
###
|
5
|
+
# Here you can set global options for users on the command line.
|
6
|
+
#
|
7
|
+
# RBCli supports commands with syntax as follows:
|
8
|
+
# toolname [options] command [parameters] [lineitem]
|
9
|
+
#
|
10
|
+
# Here you are defining the [options]. The parameters and lineitms (subcommands) are
|
11
|
+
# defined under their command blocks.
|
12
|
+
#
|
13
|
+
# The following types are supported: `:string`, `:boolean` or `:flag`, `:integer`, and `:float`
|
14
|
+
#
|
15
|
+
# If a default value is not set, it will default to `nil`.
|
16
|
+
#
|
17
|
+
# To specify multiple options, simply copy the line and modify as desired.
|
18
|
+
#
|
19
|
+
# Once parsed, option values will be placed in a hash where they can be accessed via their names as shown above where
|
20
|
+
# they are made available to your hooks and commands.
|
21
|
+
###
|
22
|
+
|
23
|
+
## Description -- (Required) -- A description that will appear when the user looks at the help with -h.
|
24
|
+
# This should describe what the application does, and if applicable, give some common usage examples.
|
25
|
+
# It can be as long as needed. Use a heredoc if desired: <<-EOF TextGoesHere EOF
|
26
|
+
description %q{<%= @vars[:description] %>}
|
27
|
+
|
28
|
+
## Option -- (Optional, Multiple) -- Add a global CLI Option
|
29
|
+
option :name, 'Give me your name', type: :string, default: 'Foo', required: false, permitted: ['Jack', 'Jill']
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Rbcli::Configurate.me do
|
2
|
+
####
|
3
|
+
# AUTOUPDATE
|
4
|
+
###
|
5
|
+
# RBCli can notify users when you have an update to your application.
|
6
|
+
# This requires your application to be published either on Rubygems.org, Github, or Github Enterprise.
|
7
|
+
# Note that only one can be enabled at a time.
|
8
|
+
# For more details on each integration, see below.
|
9
|
+
###
|
10
|
+
|
11
|
+
## Autoupdate, Github -- (Optional) -- Check for updates to this application at a GitHub repo.
|
12
|
+
# The repo should use version number tags in accordance to Github's best practices: https://help.github.com/articles/creating-releases/
|
13
|
+
#
|
14
|
+
# Note that the `access_token` can be overridden by the user via their configuration file, so it can be left as `nil`,
|
15
|
+
# which will require your users to enter their github tokens to use this feature.
|
16
|
+
# For instructions on generating a new access token, see: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
|
17
|
+
# The token is not needed if using a public repo.
|
18
|
+
#
|
19
|
+
# The `enterprise_hostname` setting allows you to point RBCli at a local GitHub Enterprise server.
|
20
|
+
#
|
21
|
+
# Setting `force_update: true` will halt execution if an update is available, forcing the user to update.
|
22
|
+
# Uncomment the line below to enable
|
23
|
+
|
24
|
+
#autoupdate github_repo: '<your_user>/<your_repo>', access_token: nil, enterprise_hostname: nil, force_update: false
|
25
|
+
|
26
|
+
|
27
|
+
## Autoupdate, Rubygems.org -- (Optional) -- Check for updates to this application on Rubygems.org
|
28
|
+
# Uncomment the line below to enable
|
29
|
+
|
30
|
+
#autoupdate gem: '<your_gem>', force_update: false
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Rbcli::Configurate.me do
|
2
|
+
####
|
3
|
+
# LOGGING
|
4
|
+
###
|
5
|
+
# These parameters set the default logging parameters for your applicaiton. Note that a user
|
6
|
+
# can override these settings by modifying their local configuration.
|
7
|
+
# If either option is set to nil, or they are not provided, logging is disabled.
|
8
|
+
###
|
9
|
+
|
10
|
+
## Log Target -- (Optional) -- Set the target for logs.
|
11
|
+
# Valid values are nil, 'STDOUT', 'STDERR', or a file path (as strings).
|
12
|
+
# Default is disabled (nil).
|
13
|
+
log_target nil
|
14
|
+
|
15
|
+
## Log Level -- (Optional) -- Set the default log_level for users.
|
16
|
+
# Valid values are nil, 0-5, or DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN.
|
17
|
+
# Default is disabled (nil).
|
18
|
+
log_level nil
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
###############################
|
2
|
+
## State Configuration Block ##
|
3
|
+
###############################
|
4
|
+
# The state-related componets
|
5
|
+
# are configured here.
|
6
|
+
###############################
|
7
|
+
Rbcli::Configurate.storage do
|
8
|
+
###
|
9
|
+
# Local State Storage
|
10
|
+
###
|
11
|
+
# Local state storage creates a hash that is automatically saved to a file locally for state persistance.
|
12
|
+
# It is accessible to all commands at: Rbcli.localstate[:yourkeyhere]
|
13
|
+
#
|
14
|
+
# Note that every update to the top level of this hash will trigger a save, and updating nested hashes will not.
|
15
|
+
# If you need to update nested hashes, you can trigger a save manually by calling `Rbcli.localstate.commit`.
|
16
|
+
# Please see the documentation for full usage details.
|
17
|
+
###
|
18
|
+
|
19
|
+
#local_state '/var/mytool/localstate', force_creation: true, halt_on_error: true # (Optional) Creates a hash that is automatically saved to a file locally for state persistance. It is accessible to all commands at Rbcli.localstate[:yourkeyhere]
|
20
|
+
|
21
|
+
|
22
|
+
###
|
23
|
+
# Remote State Storage
|
24
|
+
###
|
25
|
+
# Remote state storage creates a hash that is automatically saved to a remote database for state persistence.
|
26
|
+
# This state can be made unique to each user, or can be shared across different users of the tool.
|
27
|
+
#
|
28
|
+
# When sharing, locking should be set to `true`. Note that RBCli uses lazy-loaded, meaning the lock will
|
29
|
+
# only be acquired when absolutely needed. This behavior can be overridden manually if desired.
|
30
|
+
# For full usage details, see the documentation.
|
31
|
+
###
|
32
|
+
|
33
|
+
#remote_state_dynamodb table_name: 'mytable', region: 'us-east-1', force_creation: true, halt_on_error: true, locking: :auto # (Optional) Creates a hash that is automatically saved to a DynamoDB table. It is recommended to keep halt_on_error=true when using a shared state. Locking can be one of (:manual :auto :none) -- see the README for details
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Rbcli::Configurate.me do
|
2
|
+
####
|
3
|
+
# USER CONFIGURATION MANAGEMENT
|
4
|
+
###
|
5
|
+
# RBCli allows you to create a configuration file that your users can modify.
|
6
|
+
# Users will be able to generate their own file by running your tool with the `-g` option.
|
7
|
+
# To disable this feature, comment out the `config_userfile` line below.
|
8
|
+
###
|
9
|
+
|
10
|
+
## Config Userfile -- (Optional) -- Set location of user's config file.
|
11
|
+
#
|
12
|
+
# config_userfile <path>, merge_defaults: <optional: (true|false), default: true>, required: <optional: (true|false, default: false)
|
13
|
+
#
|
14
|
+
# If merge_defaults=true, user settings override default settings.
|
15
|
+
# If false, defaults set here are not loaded at all, and the user is required to set them.
|
16
|
+
# If required=true, application will not run if file does not exist.
|
17
|
+
config_userfile '~/.<%= @vars[:cmdname] %>', merge_defaults: true, required: false
|
18
|
+
|
19
|
+
## Config Defaults -- (Optional, Multiple) -- Load a YAML file as part of the default config.
|
20
|
+
# This can be called multiple times, and the YAML files will be merged. User config is generated from these files.
|
21
|
+
# RBCli's best practice is to leave this line commented, and instead, place all YAML files in
|
22
|
+
# the `default_user_configs` directory where they are loaded automatically.
|
23
|
+
#config_defaults 'defaults.yml'
|
24
|
+
|
25
|
+
## Config Default -- (Optional, Multiple) -- Specify an individual configuration parameter and set a default value.
|
26
|
+
# These will be included in generated user config.
|
27
|
+
config_default :myopt, description: 'Testing this', default: true
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#########################################################
|
4
|
+
### <%= @vars[:cmdname] %>
|
5
|
+
#######
|
6
|
+
## This is the main executable for <%= @vars[:cmdname] %>.
|
7
|
+
## It's job is to load and execute the application.
|
8
|
+
##
|
9
|
+
## You should not need to edit this file.
|
10
|
+
#########################################################
|
11
|
+
|
12
|
+
require 'rbcli'
|
13
|
+
require '../config/version'
|
14
|
+
|
15
|
+
#########################
|
16
|
+
## Configuration Block ##
|
17
|
+
#########################
|
18
|
+
# This block is where rbcli is configured.
|
19
|
+
# Any options marked as Optional can be commented out.
|
20
|
+
# Options marked as Multiple can be declared multiple times.
|
21
|
+
#########################
|
22
|
+
|
23
|
+
Rbcli::Configurate.me do
|
24
|
+
####
|
25
|
+
# GENERAL
|
26
|
+
###
|
27
|
+
# These parameters are for genreal information about your application.
|
28
|
+
###
|
29
|
+
|
30
|
+
## Script Name -- (Required) -- This line identifies the tool's executable on the command line.
|
31
|
+
# To change it, rename this file to the command you want and this will pick up that name automatically.
|
32
|
+
# You can change it manually if needed, but this should work for most cases.
|
33
|
+
scriptname __FILE__.split('/')[-1]
|
34
|
+
|
35
|
+
## Version Number -- (Required)
|
36
|
+
# Here we reference the same constant that we set for our Gem. If not using Rubygems you can change this to
|
37
|
+
# a version in the standard 'major.minor.patch' format (i.e.: 1.4.0)
|
38
|
+
version Project::VERSION
|
39
|
+
end
|
40
|
+
|
41
|
+
##################
|
42
|
+
## Load Project ##
|
43
|
+
##################
|
44
|
+
# Here we load the project into Rbcli
|
45
|
+
##################
|
46
|
+
Rbcli.load_project
|
47
|
+
|
48
|
+
#####################
|
49
|
+
## Parse Statement ##
|
50
|
+
#####################
|
51
|
+
# When this statement is called, the CLI will be
|
52
|
+
# parsed and code executed.
|
53
|
+
#####################
|
54
|
+
Rbcli.parse
|