luban-cli 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83a10043132409c7e0d1bf93e9543307a4810cbe
4
- data.tar.gz: 9d8f68f187e40c65457e8146cfb8b09adf5c1fa6
3
+ metadata.gz: 5e7c0fc5fe7b473f10f9eeb1ea5b3077b4036754
4
+ data.tar.gz: 9a1e0c3cd85467992f749f48dc1386419c3ce1ea
5
5
  SHA512:
6
- metadata.gz: 2e595eb672e72a9668f49dec03a3b92a09e97c214f1d5911bd9c6a0e237796c1b65ce3a5d0321daa51ef5702aa93b058ef0ac8f5bb1aeb0e53d4f3de25360ae4
7
- data.tar.gz: 1345813a8edbe2e4168971df568a4a9444f1893dee73e0e0188bda87d15b7952a85ae1479298b98fbd87db01c33ba156edc31af47260bb8bce0010c8b4a07fed
6
+ metadata.gz: 6bb0b97497b42f8061fa4a88043deef23129ab8969a0c412b1eab7de0ea1949f2865702477f50fbb51ab2085ee35c6f019347b340b9b8d7424e0530edeb54905
7
+ data.tar.gz: 86eebc55192192cffa51ee3551277e5e68d9e00cfc533e1497e641311dbe1d430941284574eeb5d59e072f373f8c9e49092278224dc741df27a4a0ef6d7997ea
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## Version 0.4.7 (Sept 28, 2016)
4
+
5
+ Minor enhancements:
6
+ * Updated README with description for tasks
7
+
8
+ Bug fixes:
9
+ * Properly handled any remaining command line arguments to opts[:__remaining__] when action method does not removes command line arguments destructively
10
+
3
11
  ## Version 0.4.6 (Sept 27, 2016)
4
12
 
5
13
  New features:
data/README.md CHANGED
@@ -481,6 +481,64 @@ end
481
481
 
482
482
  DSL method #auto_help_command is used to define a command to list all commands or help for one command. Under rare circumstances that you need to customize the help command (i.e., use a different command name like :manual), you can use DSL method #help_command which accepts the same parameters that for #command.
483
483
 
484
+ ### Tasks
485
+
486
+ A task is a special command that supports common options shared among other tasks, and usually it is the last command in a command chain.
487
+
488
+ In a typical use case, all commands have a set of common options in addition to their own. Tasks can be defined to solve this issue in a DRY way with an instance method, #add_common_task_options, in where the common options are defined. Here is a simple example demonstrating the usage of tasks:
489
+
490
+ ```ruby
491
+ require 'luban/cli'
492
+
493
+ class MyApp < Luban::CLI::Application
494
+ configure do
495
+ version '1.0.0'
496
+ desc 'Short description for the application'
497
+ long_desc 'Long description for the application'
498
+
499
+ command :tasks do
500
+ desc 'Description for tasks'
501
+
502
+ task :task1 do
503
+ desc 'Description for task 1'
504
+ argument :arg1, 'Description for arg1', type: :string
505
+ action :exec_tasks_task1
506
+ end
507
+
508
+ task :task2 do
509
+ desc 'Description for task 2'
510
+ option :opt1, 'Description for opt1', type: :integer
511
+ action :exec_tasks_task2
512
+ end
513
+ end
514
+ end
515
+
516
+ def exec_tasks_task1(**params)
517
+ puts params.inspect
518
+ end
519
+
520
+ def exec_tasks_task2(**params)
521
+ puts params.inspect
522
+ end
523
+
524
+ protected
525
+
526
+ def add_common_task_options(task)
527
+ task.switch :dry_run, "Run as a simulation", short: :d
528
+ task.switch :verbose, "Turn on verbose mode", short: :V
529
+ end
530
+ end
531
+
532
+ MyApp.start
533
+
534
+ $ ruby my_app.rb tasks task1 arg1 -d -V
535
+ {:args=>{:arg1=>"arg1"}, :opts=>{:help=>nil, :dry_run=>true, :verbose=>true, :__remaining__=>[]}}
536
+
537
+ $ ruby my_app.rb tasks task2 -d
538
+ {:args=>{}, :opts=>{:opt1=>nil, :help=>nil, :dry_run=>true, :verbose=>nil, :__remaining__=>[]}}
539
+
540
+ ```
541
+
484
542
  ### Command injection
485
543
 
486
544
  Commands can be defined directly within the Luban app class like examples shown in the previous sections. In addition, commands can be defined separately and injected into a given Luban app later. Command definition can be also namespaced by using module. With this feature, commands can be designed in a more re-usable and scalable way. This feature also implies that Luban CLI application supports namespaced commands.
@@ -131,7 +131,7 @@ module Luban
131
131
  else
132
132
  validate_required_options
133
133
  validate_required_arguments
134
- result[:opts][:__remaining__] = argv
134
+ result[:opts][:__remaining__] = result[:argv]
135
135
  yield args: result[:args], opts: result[:opts]
136
136
  if has_commands?
137
137
  dispatch_command(cmd: result[:cmd], argv: result[:argv])
@@ -1,5 +1,5 @@
1
1
  module Luban
2
2
  module CLI
3
- VERSION = "0.4.6"
3
+ VERSION = "0.4.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luban-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rubyist Chi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler