tcollier-commando 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fb82072f6cdcc9e0520a32ade43924acd20dfff
4
- data.tar.gz: d856cb9045676d0954ea1688f229dcbbb3c2772e
3
+ metadata.gz: b409b80542b9797e8624584c37b6850b16ae7834
4
+ data.tar.gz: 7379329a9a815040d178da7008625add71b56d97
5
5
  SHA512:
6
- metadata.gz: 3f9309d4f4f84b37fd4036c64fc0463a35650bc79cdf104298018c982c8dfd5fb2439b86b20a005c2d96add8e852f0f7263f7f6bda5daf0474a158c6ed3a4005
7
- data.tar.gz: 002b84ff2a1f5b49e51a4bc4992e1f36a20675d78f46ed51feab96472fdd7e1420fd1bb351dda594787e146b969f6d2d390e29c8bd3210e53e3d9991a9411fc8
6
+ metadata.gz: 876079a43c673ac8e7817ea08da0222ccda8cecca6e98cc4f5ac17655f17c2b000e0a57aa3e4add91f46890239a47c4be8eef90d2ae7111d484e1ccfae4a7bab
7
+ data.tar.gz: d1baa3112c277c030cb8d35fe80447aa7fe0d5bf3fe647288c597d541a44cbed9265ab24e3b907b44c7cda3d5eceee396260b8c057031f9671428ce550f2606e
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ *.gem
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  A command line interface builder with Readline support
4
4
 
5
+ ## Versions
6
+
7
+ * `0.1.0` - Initial release
8
+ * `0.1.1` - Alphabetize commands printed via `help`
9
+
5
10
  ## Installation
6
11
 
7
12
  Add this line to your application's Gemfile:
@@ -34,12 +39,24 @@ end
34
39
 
35
40
  ### Actions
36
41
 
37
- To support a new command, you must register it with the command the user will
38
- type (e.g. `help`), a class/module/instance that responds to `#perform(args, output:)`,
39
- where `args` is an `Array<String>` of the extra words the follow the command
40
- (e.g. if the user types `addfriend mary jane`, then the args are `['mary', 'jane']`)
41
- and `output` is the `IO` instance that any messages should be written to. By
42
- default `IO` is `$stdout`
42
+ To support a new command, you must register it with
43
+
44
+ * The command the user will type (e.g. `addfriend`).
45
+ * A class/module/instance that fills the `Action` role.
46
+ * A brief description of what the command does and what arguments it takes, if any.
47
+
48
+ #### Action role
49
+
50
+ The `Action role` responds to `perform(args, output:)`, where
51
+
52
+ * `args` [`Array<String>`] - the list of the extra words that follow the command
53
+ (e.g. if the user types `addfriend mary jane`, then the args are `['mary', 'jane']`).
54
+ * `output` [`IO`] - the IO instance that any messages should be written to.
55
+
56
+ If the arguments are not formatted correctly (e.g. the user missed an argument),
57
+ then method should raise a `Commando::ValidationError` with a descriptive message.
58
+
59
+ #### Default actions
43
60
 
44
61
  A few default actions have been registered
45
62
 
@@ -47,6 +64,11 @@ A few default actions have been registered
47
64
  * history - Prints the history of commands entered so far
48
65
  * quit - Exits the program
49
66
 
67
+ ## Usage
68
+
69
+ Once commando is configured, simply run `Commando.start` to enter the command
70
+ line interface.
71
+
50
72
  ## Contributing
51
73
 
52
74
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/commando. 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.
@@ -6,7 +6,8 @@ module Commando
6
6
  module Help
7
7
  def self.perform(args:, output: $stdout)
8
8
  output.puts "Valid commands are"
9
- Commando.config.each_action do |command, description|
9
+ descriptions = Commando.config.descriptions
10
+ descriptions.sort_by { |cmd, _| cmd }.each do |command, description|
10
11
  output.puts " * #{command} - #{description}"
11
12
  end
12
13
  end
@@ -4,6 +4,7 @@ require_relative 'action/quit'
4
4
 
5
5
  module Commando
6
6
  ActionConfig = Struct.new(:action_class, :description)
7
+ private_constant :ActionConfig
7
8
 
8
9
  # Manage the configuration for the actions available to the CLI
9
10
  class Config
@@ -52,11 +53,10 @@ module Commando
52
53
  mapping[command]&.action_class
53
54
  end
54
55
 
55
- # Iterate through each of the registered commands, yielding the command
56
- # string and the description
57
- def each_action(&block)
58
- mapping.each do |command, action_config|
59
- yield command, action_config.description
56
+ # @return [Hash<String, String>] a map of commands to their descriptions
57
+ def descriptions
58
+ mapping.map.with_object({}) do |(command, action_config), hash|
59
+ hash[command] = action_config.description
60
60
  end
61
61
  end
62
62
 
@@ -1,3 +1,3 @@
1
1
  module Commando
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcollier-commando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Collier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler