Module: Dynomite
- Extended by:
- Core
- Defined in:
- lib/dynomite/item.rb,
lib/dynomite.rb,
lib/dynomite/cli.rb,
lib/dynomite/core.rb,
lib/dynomite/seed.rb,
lib/dynomite/error.rb,
lib/dynomite/query.rb,
lib/dynomite/types.rb,
lib/dynomite/client.rb,
lib/dynomite/config.rb,
lib/dynomite/engine.rb,
lib/dynomite/waiter.rb,
lib/dynomite/command.rb,
lib/dynomite/install.rb,
lib/dynomite/version.rb,
lib/dynomite/completer.rb,
lib/dynomite/migration.rb,
lib/dynomite/autoloader.rb,
lib/dynomite/associations.rb,
lib/dynomite/reserved_words.rb,
lib/dynomite/associations/has_one.rb,
lib/dynomite/associations/has_many.rb,
lib/dynomite/associations/belongs_to.rb,
lib/dynomite/associations/association.rb,
lib/dynomite/associations/many_association.rb,
lib/dynomite/associations/single_association.rb,
lib/dynomite/associations/has_and_belongs_to_many.rb
Overview
Code Explanation:
There are 3 types of things to auto-complete:
1. command: the command itself
2. parameters: command parameters.
3. options: command options
Here’s an example:
mycli hello name --from me
* command: hello
* parameters: name
* option: --from
When command parameters are done processing, the remaining completion words will be options. We can tell that the command params are completed based on the method arity.
## Arity
For example, say you had a method for a CLI command with the following form:
ufo scale service count --cluster development
It’s equivalent ruby method:
scale(service, count) = has an arity of 2
So typing:
ufo scale service count [TAB] # there are 3 parameters including the "scale" command according to Thor's CLI processing.
So the completion should only show options, something like this:
--noop --verbose --cluster
## Splat Arguments
When the ruby method has a splat argument, it’s arity is negative. Here are some example methods and their arities.
ship(service) = 1
scale(service, count) = 2
ships(*services) = -1
foo(example, *rest) = -2
Fortunately, negative and positive arity values are processed the same way. So we take simply take the absolute value of the arity and process it the same.
Here are some test cases, hit TAB after typing the command:
dynomite completion
dynomite completion hello
dynomite completion hello name
dynomite completion hello name --
dynomite completion hello name --noop
dynomite completion
dynomite completion sub:goodbye
dynomite completion sub:goodbye name
## Subcommands and Thor::Group Registered Commands
Sometimes the commands are not simple thor commands but are subcommands or Thor::Group commands. A good specific example is the ufo tool.
* regular command: ufo ship
* subcommand: ufo docker
* Thor::Group command: ufo init
Auto-completion accounts for each of these type of commands.
Defined Under Namespace
Modules: Associations, Client, Core, Help, Types Classes: Autoloader, CLI, Command, Completer, Config, Engine, Erb, Error, Install, Item, Migration, Query, Seed, Waiter
Constant Summary collapse
- VERSION =
"2.0.3"
- RESERVED_WORDS =
%w[ as_json attributes attrs columns destroy fields find getter hash_key hash_key_field key_schema new_record param_name partition_key partition_key_field range_key range_key_field replace save scan setter sort_key_field sort_key_field_field table_name ].freeze