runfile 1.0.0.rc4 → 1.0.1

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
  SHA256:
3
- metadata.gz: ab0dde51597dac5b5f75e8c7fe4fd627d94b70251a9f7ada897fad07f32573fc
4
- data.tar.gz: aa612294f0247bcfed789fa7a9704798f611ec83dbb80a55fe9c18eb85ad6d07
3
+ metadata.gz: b5a340ad5324cc9b24104fc460c171300cc2ab9690bb8bdfa2b38442b3ddf81a
4
+ data.tar.gz: e3f0fe2e7c4ba4fca9058d10f5caffc2daa76d5f0810aa5a63d646d2a23347d4
5
5
  SHA512:
6
- metadata.gz: cc5ed99c7b6cd47d7f3a64418ac62698f46c5e5ee1e55edb3bdf18ef157e4764efadd874ab2767a0be50ee98e0592195546d63c6f988607cb25cc6ce9de03cd8
7
- data.tar.gz: b6d0ff5c3e8fd53b048c2e5b35ebf180ef2a4f44e05b2a271e7defb572ad654258f140bcb40fa3048b84a999201e7ff5a3067d3db4ab4835c5f8f8f3aff1b990
6
+ metadata.gz: 0f94f10d4feda0300878584b68c1af769bc1a81392ee52f7716d89d0d7fe376cf9d20cc2cbb8bc0ef35d5574b469de038df67e99dbaa0a077ca4fed7a7cb548c
7
+ data.tar.gz: 5983f010e720484acdb6b013248c32f4ed104180e7fc05218c93abfaf1a3eea7775b95e7e6e7cbe2c0871316056fe4d99c27b7e1b93b13524782015199a66a8a
data/README.md CHANGED
@@ -9,15 +9,16 @@
9
9
 
10
10
  ---
11
11
 
12
- A beautiful command line application framework
13
- Rake-inspired - Docopt inside
12
+ A beautiful command line utility builder
13
+ Rake-inspired Docopt inside
14
+ **[runfile.dannyb.co](https://runfile.dannyb.co)**
14
15
 
15
16
  ---
16
17
 
17
18
  </div>
18
19
 
19
- **Runfile** lets you create command line applications in a way similar
20
- to [Rake](https://github.com/ruby/rake), but with the full power of
20
+ **Runfile** lets you create command line tools in a way similar to
21
+ [Rake](https://github.com/ruby/rake), but with the full power of
21
22
  [Docopt](http://docopt.org/) command line options.
22
23
 
23
24
  You create a `runfile`, and execute commands with
@@ -26,15 +27,9 @@ You create a `runfile`, and execute commands with
26
27
  Runfile is designed primarily for Ruby developers, but if you need to add a
27
28
  command line "toolbelt" for your projects, you can use it regardless.
28
29
 
29
- ## Pre-release Notice
30
-
31
- Note that this README describes the not yet released 1.0.0 version.
32
- See [runfile.dannyb.co](https://runfile.dannyb.co/) for the stable release
33
- documentation.
34
-
35
30
  ## Demo
36
31
 
37
- ![Runfile Demo](demo.svg "Runfile Demo")
32
+ ![Runfile Demo](support/cast.gif "Runfile Demo")
38
33
 
39
34
  ## Install
40
35
 
@@ -110,7 +105,7 @@ Options:
110
105
  Show this message
111
106
  ```
112
107
 
113
- ## Examples
108
+ ### More Examples
114
109
 
115
110
  You can learn almost everything there is to know about runfile from the
116
111
  [examples](https://github.com/DannyBen/runfile/tree/master/examples#readme).
@@ -129,56 +124,67 @@ Note that the current user guide is for the stable version 0.12.0.
129
124
 
130
125
  ## Breaking Changes in 1.0.0
131
126
 
132
- If you are using a version earlier than 1.0, note that the upcoming release
133
- 1.0.0 includes some breaking changes. You can read more about them in[this Pull
134
- Request](https://github.com/DannyBen/runfile/pull/50).
127
+ If you are using a version earlier than 1.0, note that version 1.0.0 includes
128
+ some breaking changes. You can read more about them in
129
+ [this Pull Request](https://github.com/DannyBen/runfile/pull/50).
135
130
 
136
131
  ### Upgrading to 1.0.0
137
132
 
138
- ### No more `.runfile` config
133
+ <details>
134
+ <summary>Show section</summary>
135
+
136
+ ### No more `.runfile` config
137
+
138
+ If you have used the multi-runfile config file, this no longer exists.
139
+ Use a standard `runfile` instead, along with the `import` directive.
140
+
141
+ ### No more `action :global`
142
+
143
+ If you have used the `action :global do` notation, this is replaced with the
144
+ simpler use `action do` instead. Also, there is no more need for
145
+ empty `usage ''`, just delete it if you have it in your runfiles.
146
+
147
+ ### No more `execute` directive
139
148
 
140
- If you have used the multi-runfile config file, this no longer exists.
141
- Use a standard `runfile` instead, along with the `import` directive.
149
+ If you have used it to cross-call other actions, it is no longer available. As
150
+ an alternative, you can define common code in separate classes and `require`
151
+ them, or use the new `helpers` directive to define functions that will be
152
+ available to all actions.
142
153
 
143
- ### No more `action :global`
154
+ ### Code outside of actions should be inside `helpers`
144
155
 
145
- If you have used the `action :global do` notation, this is replaced with the
146
- simpler use `action do` instead. Also, there is no more need for
147
- empty `usage ''`, just delete it if you have it in your runfiles.
156
+ If your runfiles include other ruby code, especially `def method`, you should
157
+ now use the new `helpers` block and tuck this code inside it.
148
158
 
149
- ### No more `execute` directive
159
+ ### No more need for `trap(:INT)`
150
160
 
151
- If you have used it to cross-call other actions, it is no longer available. As
152
- an alternative, you can define common code in separate classes and `require`
153
- them, or use the new `helpers` directive to define functions that will be
154
- available to all actions.
161
+ If your old runfiles trap the `Interrupt` signal, there is no longer a need to
162
+ do so, as it is trapped by default.
155
163
 
156
- ### No more need for `trap(:INT)`
164
+ ### Colsole is included
157
165
 
158
- If your old runfiles trap the `Interrupt` signal, there i no longer a need to
159
- do so, as it is trapped by default.
166
+ If your runfiles `required` and `include` Colsole, there is no longer a need to
167
+ do it. Colsole is bundled and available in actions.
160
168
 
161
- ### Colsole is included
169
+ ### Long flags before short flags
162
170
 
163
- If your runfiles `required` and `include` Colsole, there is no longer a need to
164
- do it. Colsole is bundled and available in actions.
171
+ This is a cosmetic change for consistency. All generated output shows long flags
172
+ before short flags `--force, -f` instead of `-f, --force`. Update your custom
173
+ `usage` directives accordingly.
165
174
 
166
- ### Long flags before short flags
175
+ ### Examples no longer add implicit 'run'
167
176
 
168
- This is a cosmetic change for consistency. All generated output shows long flags
169
- before short flags `--force, -f` instead of `-f, --force`. Update your custom
170
- `usage` directives accordingly.
177
+ If you were using the `example` directive, it will no longer add the initial
178
+ `run` in front of your examples. Add it yourself. This is intended to allow
179
+ providing more elaborate examples.
171
180
 
172
- ### Examples no longer add implicit 'run'
181
+ ### RunfileTasks
173
182
 
174
- If you were using the `example` directive, it will no longer add the initial
175
- `run` in front of your examples. Add it yourself. This is intended to allow
176
- providing more elaborate examples.
183
+ The `RunfileTasks` gem is also released as a pre-release, if you are using it
184
+ make sure to install the latest release candidate.
177
185
 
178
- ### RunfileTasks
186
+ </details>
179
187
 
180
- The `RunfileTasks` gem is also released as a pre-release, if you are using it
181
- make sure to install the latest release candidate.
182
188
 
183
189
  ## Contributing / Support
184
190
 
@@ -1,7 +1,7 @@
1
1
  module Runfile
2
2
  # Represents a single action inside a {Userfile} and executes its block
3
3
  # on demand. Properties of this class are populated by the {DSL} module when
4
- # running a {Userfile}.
4
+ # the runfile is executed.
5
5
  class Action
6
6
  include Inspectable
7
7
 
@@ -26,7 +26,7 @@ module Runfile
26
26
 
27
27
  instance_eval do
28
28
  host.helpers.each { |b| b.call args }
29
- block.call args
29
+ block.call args if block
30
30
  end
31
31
  end
32
32
 
@@ -34,10 +34,6 @@ module Runfile
34
34
  @name = value&.to_s
35
35
  end
36
36
 
37
- def names
38
- name ? [name, shortcut].compact : ['(default)']
39
- end
40
-
41
37
  def prefix
42
38
  host&.full_name
43
39
  end
@@ -58,6 +54,12 @@ module Runfile
58
54
  @usages ||= []
59
55
  end
60
56
 
57
+ private
58
+
59
+ def names
60
+ name.empty? ? [] : [name, shortcut].compact
61
+ end
62
+
61
63
  def validate_context
62
64
  host.required_contexts.each do |varname, default|
63
65
  next if host.context[varname]
@@ -2,8 +2,6 @@ module Runfile
2
2
  module DSL
3
3
  # Commands
4
4
 
5
- attr_reader :default_action
6
-
7
5
  def action(name = nil, shortcut = nil, &block)
8
6
  current_action.block = block
9
7
  current_action.name = name.to_s
@@ -123,7 +121,6 @@ module Runfile
123
121
  def finalize_current_action(name)
124
122
  key = name.empty? ? :default : name
125
123
  actions[key] = current_action
126
- @default_action = current_action unless name
127
124
  @current_action = nil
128
125
  end
129
126
 
@@ -10,4 +10,5 @@ module Runfile
10
10
  class ActionNotFound < UserError; end
11
11
  class GemNotFound < UserError; end
12
12
  class SyntaxError < UserError; end
13
+ class DocoptError < SyntaxError; end
13
14
  end
@@ -1,6 +1,6 @@
1
1
  module Runfile
2
2
  # Finds the path of an installed or bundled gem
3
- # Adapted from Rubocop <https://github.com/rubocop/rubocop/blob/master/lib/rubocop/config_loader_resolver.rb#L268>
3
+ # Adapted from [Rubocop](https://github.com/rubocop/rubocop/blob/master/lib/rubocop/config_loader_resolver.rb#L268)
4
4
  class GemFinder
5
5
  class << self
6
6
  def find(gem_name, file = nil)
@@ -11,9 +11,11 @@ module Runfile
11
11
  private
12
12
 
13
13
  def call_docopt(docopt, version: nil, argv: nil)
14
- Docopt.docopt docopt, argv: argv, version: version
15
- rescue Docopt::Exit => e
14
+ DocoptNG.docopt docopt, argv: argv, version: version
15
+ rescue DocoptNG::Exit => e
16
16
  raise ExitWithUsage, e.message
17
+ rescue DocoptNG::DocoptLanguageError => e
18
+ raise DocoptError, "There is an error in your runfile:\nnb`#{e.message}`"
17
19
  end
18
20
  end
19
21
  end
@@ -77,9 +77,11 @@ module Runfile
77
77
 
78
78
  def run(argv = [])
79
79
  eval_code
80
- argv = transform_argv argv if argv.any?
81
80
 
82
- found_guest = find_guest argv
81
+ if argv.any?
82
+ argv = expand_shortcuts argv
83
+ found_guest = find_guest argv
84
+ end
83
85
 
84
86
  if found_guest
85
87
  found_guest.run argv
@@ -128,9 +130,19 @@ module Runfile
128
130
  exit_code if exit_code.is_a? Integer
129
131
  end
130
132
 
131
- def transform_argv(argv)
133
+ # Shortcuts will always appear after the name, so we split argv to
134
+ # name (array), shortcut wannabe (string), rest of the args (array).
135
+ # Then, if the shortcut wannabe is a match, we stitch the new argv back
136
+ # together, with its expansion.
137
+ def expand_shortcuts(argv)
138
+ size = id.size
139
+
140
+ p1 = argv[0...size]
141
+ p2 = argv[size]
142
+ p3 = argv[(size + 1)..]
143
+
132
144
  shortcuts.each do |from, to|
133
- return Shellwords.split(to) + argv[1..] if from == argv[0]
145
+ return p1 + Shellwords.split(to) + p3 if from == p2
134
146
  end
135
147
 
136
148
  argv
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = '1.0.0.rc4'
2
+ VERSION = '1.0.1'
3
3
  end
data/lib/runfile.rb CHANGED
@@ -1,13 +1,8 @@
1
1
  require 'gtx'
2
- require 'docopt'
2
+ require 'docopt_ng'
3
3
  require 'colsole'
4
4
  require 'requires'
5
5
 
6
6
  requires 'runfile/exceptions'
7
7
  requires 'runfile/concerns'
8
8
  requires 'runfile'
9
-
10
- if ENV['BYEBUG']
11
- require 'byebug'
12
- require 'lp'
13
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc4
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-28 00:00:00.000000000 Z
11
+ date: 2023-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -31,19 +31,19 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
33
33
  - !ruby/object:Gem::Dependency
34
- name: docopt
34
+ name: docopt_ng
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.6'
39
+ version: '0.7'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.6'
46
+ version: '0.7'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: gtx
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -144,11 +144,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
144
  version: '2.7'
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
- - - ">"
147
+ - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 1.3.1
149
+ version: '0'
150
150
  requirements: []
151
- rubygems_version: 3.4.5
151
+ rubygems_version: 3.4.6
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Local command line for your projects