runfile 1.0.0.rc3 → 1.0.0.rc4

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: 87fc70007827b06c5dc191a36501383e7cbbff057ab8b237e4fd1c6ecc1cc359
4
- data.tar.gz: 63a028d2937711589b69f73003ddc367326fd0dc2d4decfad10e29e3b1d44078
3
+ metadata.gz: ab0dde51597dac5b5f75e8c7fe4fd627d94b70251a9f7ada897fad07f32573fc
4
+ data.tar.gz: aa612294f0247bcfed789fa7a9704798f611ec83dbb80a55fe9c18eb85ad6d07
5
5
  SHA512:
6
- metadata.gz: ebdb28b94a76ad187975256fb7e3ab9d423e3b86af833f20b52d91e74886b4b03fd2a8849bdf1f50cd97c26978742f42a3522f375bd3d6567f5bb46c675b9ac2
7
- data.tar.gz: fd87911f07745dff40c82bb8c4245cf309eae294799dbee320521c7d38b50a0c9575d9ad15fde44974c18639c05c3223712cf517389c149e6a9bd97020344b02
6
+ metadata.gz: cc5ed99c7b6cd47d7f3a64418ac62698f46c5e5ee1e55edb3bdf18ef157e4764efadd874ab2767a0be50ee98e0592195546d63c6f988607cb25cc6ce9de03cd8
7
+ data.tar.gz: b6d0ff5c3e8fd53b048c2e5b35ebf180ef2a4f44e05b2a271e7defb572ad654258f140bcb40fa3048b84a999201e7ff5a3067d3db4ab4835c5f8f8f3aff1b990
data/README.md CHANGED
@@ -32,9 +32,6 @@ Note that this README describes the not yet released 1.0.0 version.
32
32
  See [runfile.dannyb.co](https://runfile.dannyb.co/) for the stable release
33
33
  documentation.
34
34
 
35
- During the pre-release phase, the `run` executable is called `runn` instead,
36
- to allow running both the stable and pre-release version side by side.
37
-
38
35
  ## Demo
39
36
 
40
37
  ![Runfile Demo](demo.svg "Runfile Demo")
@@ -55,8 +52,8 @@ $ vi runfile # edit the runfile
55
52
 
56
53
  ## Example
57
54
 
58
- A simple `runfile` looks like this. You can get this template by running `run
59
- new` ()in a directory without other runfiles).
55
+ A simple `runfile` looks like this. You can get this template by running
56
+ `run new` (in a directory without other runfiles).
60
57
 
61
58
  ```ruby
62
59
  title 'Greeter'
@@ -172,6 +169,12 @@ This is a cosmetic change for consistency. All generated output shows long flags
172
169
  before short flags `--force, -f` instead of `-f, --force`. Update your custom
173
170
  `usage` directives accordingly.
174
171
 
172
+ ### Examples no longer add implicit 'run'
173
+
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.
177
+
175
178
  ### RunfileTasks
176
179
 
177
180
  The `RunfileTasks` gem is also released as a pre-release, if you are using it
data/bin/{runn → run} RENAMED
File without changes
@@ -0,0 +1,21 @@
1
+ title 'Shortcut for an action'
2
+ summary 'Providing an alias shortcut for actions'
3
+
4
+ # $ run greet :
5
+ # $ run g : will both execute this block
6
+ action :greet, :g do
7
+ say 'r`Greetings`'
8
+ end
9
+
10
+ # $ run salute
11
+ # $ run s --red
12
+ #
13
+ # Notice the explicit `usage` which is required when when parameters (--red)
14
+ # are needed. In this case, to support the shortcut you need to provide it
15
+ # as (salute | s)
16
+ usage '(salute | s) [--red]'
17
+ option '--red', 'In red'
18
+ action :salute, :s do |args|
19
+ color = args['--red'] ? 'r' : 'b'
20
+ say "#{color}`Salutations`"
21
+ end
@@ -8,6 +8,7 @@ option '--color, -c CODE', 'One letter color code [default: g]'
8
8
  option '--bold, -b', 'Show in bold'
9
9
  param 'MESSAGE', 'Message to say'
10
10
  env_var 'COLOR', 'Set color code (same as --color)'
11
+ env_var 'API_KEY', 'Set API Key'
11
12
  example 'run say hello'
12
13
  example 'run say hello -cr --bold'
13
14
  action :say, :s do |args|
@@ -1,31 +1,12 @@
1
- title 'Shortcut for an action'
2
- summary 'Providing an alias shortcut for actions can be done in one of two ways'
1
+ import 'server'
3
2
 
4
- # $ run greet :
5
- # $ run g : will both execute this block
6
- shortcut :g
7
- action :greet do
8
- say 'r`Greetings`'
9
- end
10
-
11
- # $ run salute
12
- # $ run s --red
13
- #
14
- # Notice the explicit `usage` which is required when when parameters (--red)
15
- # are needed. In this case, to support the shortcut you need to provide it
16
- # as (salute | s)
17
- usage '(salute | s) [--red]'
18
- option '--red', 'In red'
19
- shortcut :s
20
- action :salute do |args|
21
- color = args['--red'] ? 'r' : 'b'
22
- say "#{color}`Salutations`"
23
- end
3
+ # Create command shortcuts
4
+ shortcut 'sayhi', 'hello "new runfile user"'
5
+ shortcut 's', 'server start'
24
6
 
25
- # $ run toast
26
- # $ run t
27
- #
28
- # Shortcut may also be provided as a second argument to the `action` directive
29
- action :toast, :t do
30
- say 'Toasts'
7
+ usage 'hello [NAME]'
8
+ help 'Say hello'
9
+ action 'hello' do |args|
10
+ name = args['NAME'] || 'You...'
11
+ say "Hello g`#{name}`"
31
12
  end
@@ -0,0 +1,3 @@
1
+ action :start do
2
+ puts 'server is starting...'
3
+ end
@@ -8,16 +8,13 @@ module Runfile
8
8
  attr_reader :name, :shortcut
9
9
  attr_accessor :block, :help, :host
10
10
 
11
- def full_name
12
- @full_name ||= if shortcut
13
- "#{prefix} (#{name} | #{shortcut})".strip
14
- else
15
- "#{prefix} #{name}".strip
16
- end
11
+ def command_string
12
+ result = names.join(', ')
13
+ result.empty? ? '(default)' : result
17
14
  end
18
15
 
19
16
  def implicit_usages
20
- usages.empty? ? [full_name] : usages
17
+ usages.empty? ? [usage_string] : usages
21
18
  end
22
19
 
23
20
  def inspectable
@@ -49,6 +46,14 @@ module Runfile
49
46
  @shortcut = value&.to_s
50
47
  end
51
48
 
49
+ def usage_string
50
+ @usage_string ||= if shortcut
51
+ "#{prefix} (#{name} | #{shortcut})".strip
52
+ else
53
+ "#{prefix} #{name}".strip
54
+ end
55
+ end
56
+
52
57
  def usages
53
58
  @usages ||= []
54
59
  end
@@ -56,8 +56,8 @@ module Runfile
56
56
  @required_contexts ||= {}
57
57
  end
58
58
 
59
- def shortcut(name)
60
- current_action.shortcut = name.to_s
59
+ def shortcut(from, to)
60
+ shortcuts[from] = to
61
61
  end
62
62
 
63
63
  def summary(text = nil)
@@ -74,6 +74,7 @@ module Runfile
74
74
 
75
75
  def usage(message)
76
76
  message = "#{name} #{message}" if name
77
+ message = "#{host.full_name} #{message}".strip if host
77
78
  current_action.usages.push message
78
79
  end
79
80
 
@@ -105,12 +106,16 @@ module Runfile
105
106
  @helper_blocks ||= []
106
107
  end
107
108
 
109
+ def imports
110
+ @imports ||= {}
111
+ end
112
+
108
113
  def options
109
114
  @options ||= {}
110
115
  end
111
116
 
112
- def imports
113
- @imports ||= {}
117
+ def shortcuts
118
+ @shortcuts ||= {}
114
119
  end
115
120
 
116
121
  private
@@ -56,9 +56,9 @@ module Runfile
56
56
  end
57
57
 
58
58
  def rootfile
59
- if File.exist? 'runfile'
59
+ if File.file? 'runfile'
60
60
  Userfile.new 'runfile'
61
- elsif File.exist? 'Runfile'
61
+ elsif File.file? 'Runfile'
62
62
  Userfile.new 'Runfile'
63
63
  end
64
64
  end
@@ -24,6 +24,10 @@ module Runfile
24
24
  @code ||= File.read(path)
25
25
  end
26
26
 
27
+ def commands
28
+ actions.values.select(&:help)
29
+ end
30
+
27
31
  def eval_code
28
32
  return if evaluated?
29
33
 
@@ -36,11 +40,23 @@ module Runfile
36
40
  end
37
41
 
38
42
  def full_name
39
- id.join ' '
43
+ @full_name ||= id.join ' '
44
+ end
45
+
46
+ def guests
47
+ @guests ||= begin
48
+ result = imports.map do |glob, context|
49
+ Dir.glob("#{glob}.runfile").sort.map do |guest_path|
50
+ Userfile.new guest_path, context: context, host: self
51
+ end
52
+ end
53
+
54
+ result.flatten
55
+ end
40
56
  end
41
57
 
42
58
  def id
43
- if host
59
+ @id ||= if host
44
60
  (host.id + [name]).compact
45
61
  else
46
62
  [name].compact
@@ -56,12 +72,15 @@ module Runfile
56
72
  end
57
73
 
58
74
  def rootfile?
59
- basename.casecmp? 'runfile'
75
+ @rootfile ||= basename.casecmp? 'runfile'
60
76
  end
61
77
 
62
78
  def run(argv = [])
63
79
  eval_code
80
+ argv = transform_argv argv if argv.any?
81
+
64
82
  found_guest = find_guest argv
83
+
65
84
  if found_guest
66
85
  found_guest.run argv
67
86
  else
@@ -69,24 +88,12 @@ module Runfile
69
88
  end
70
89
  end
71
90
 
72
- def commands
73
- actions.values.select(&:help)
74
- end
75
-
76
- def guests
77
- @guests ||= begin
78
- result = imports.map do |glob, context|
79
- Dir.glob("#{glob}.runfile").sort.map do |guest_path|
80
- Userfile.new guest_path, context: context, host: self
81
- end
82
- end
91
+ private
83
92
 
84
- result.flatten
85
- end
93
+ def docopt
94
+ @docopt ||= render 'userfile', context: self
86
95
  end
87
96
 
88
- private
89
-
90
97
  def find_action(args)
91
98
  acts = actions.values
92
99
  acts.find { |a| args[a.name] } ||
@@ -121,8 +128,12 @@ module Runfile
121
128
  exit_code if exit_code.is_a? Integer
122
129
  end
123
130
 
124
- def docopt
125
- @docopt ||= render 'userfile', context: self
131
+ def transform_argv(argv)
132
+ shortcuts.each do |from, to|
133
+ return Shellwords.split(to) + argv[1..] if from == argv[0]
134
+ end
135
+
136
+ argv
126
137
  end
127
138
  end
128
139
  end
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = '1.0.0.rc3'
2
+ VERSION = '1.0.0.rc4'
3
3
  end
@@ -34,7 +34,7 @@ end
34
34
  if commands.any? || guests.any?
35
35
  > Commands:
36
36
  commands.each do |action|
37
- = " nb`#{action.names.join(', ')}`"
37
+ = " nb`#{action.command_string}`"
38
38
  = word_wrap " #{action.help}"
39
39
  >
40
40
  end
@@ -78,6 +78,15 @@ if env_vars.any?
78
78
  env_vars.each do |name, help|
79
79
  = " #{name}"
80
80
  = word_wrap " #{help}"
81
+ >
82
+ end
83
+ end
84
+
85
+ if shortcuts.any?
86
+ > Shortcuts:
87
+ maxlen = shortcuts.keys.map(&:size).max
88
+ shortcuts.each do |from, to|
89
+ = " nb`#{from.ljust maxlen}` #{to}"
81
90
  end
82
91
  >
83
92
  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.rc3
4
+ version: 1.0.0.rc4
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-27 00:00:00.000000000 Z
11
+ date: 2023-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -81,12 +81,13 @@ dependencies:
81
81
  description: Build expressive command line utilities for your projects.
82
82
  email: db@dannyben.com
83
83
  executables:
84
- - runn
84
+ - run
85
85
  extensions: []
86
86
  extra_rdoc_files: []
87
87
  files:
88
88
  - README.md
89
- - bin/runn
89
+ - bin/run
90
+ - examples/action-shortcut/runfile
90
91
  - examples/default-action-2/runfile
91
92
  - examples/default-action-2/server.runfile
92
93
  - examples/default-action/runfile
@@ -107,6 +108,7 @@ files:
107
108
  - examples/require-context/runfile
108
109
  - examples/require-context/server.runfile
109
110
  - examples/shortcut/runfile
111
+ - examples/shortcut/server.runfile
110
112
  - lib/runfile.rb
111
113
  - lib/runfile/action.rb
112
114
  - lib/runfile/concerns/dsl.rb