runfile 0.10.2 → 0.11.2

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: bcc3c5aac5c6d47e26432ed9ed5303e38dfdca077fe832f71767a42504edf828
4
- data.tar.gz: a30f05d36eb902902ad484daf51b93956ddc87a386e27d08c0acb2d6fecdb1ea
3
+ metadata.gz: f1e4e930d902a8bb8db9d283e1cf7c33fb26c5e1dfdf77b03d5be0a3acc01609
4
+ data.tar.gz: cf2bf1976c2dee358a8bbd2b9465b871bc6c9630c0ca7f091000b2464615370c
5
5
  SHA512:
6
- metadata.gz: 51dec6b06b052b6aa6ca13d7b07a1c7da1fc06c24f07896be9384dd28b6a4ed8d4a6e874b9b55cc02f159ce4ebc2b47a02b09af00d9c81abcd09f0a485b0dcc0
7
- data.tar.gz: f46f5bd6533fc1d1f0d6f607d06ae2b4c1c99916a2cb0a0fd10c011ed75bdba50e3f80cad6c502f46ec7a4b4c03676aca75a00802f4d179a053f6aa6d7c1a1bb
6
+ metadata.gz: 9eaadbedb085b6a8ef13078327b2260c82fc86baebf2292868eb7d37c166206e8b529a82a67e39fbe3a1087271308d5f750ff07bea8c515e9b065d7e413cdf65
7
+ data.tar.gz: f837dd093b39741dabc2e67813bcd21f9ff7bdac3b52cb90990fe9b568f90801e5c344e697224ddce095af478fc7e92ace4d5be8867c97827b4627f93dd7535e
data/README.md CHANGED
@@ -2,8 +2,7 @@ Runfile - If Rake and Docopt had a baby
2
2
  ==================================================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/runfile.svg)](https://badge.fury.io/rb/runfile)
5
- [![Build Status](https://travis-ci.com/DannyBen/runfile.svg?branch=master)](https://travis-ci.com/DannyBen/runfile)
6
- [![BCH compliance](https://bettercodehub.com/edge/badge/DannyBen/runfile?branch=master)](https://bettercodehub.com/results/DannyBen/runfile)
5
+ [![Build Status](https://github.com/DannyBen/runfile/workflows/Test/badge.svg)](https://github.com/DannyBen/runfile/actions?query=workflow%3ATest)
7
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/81cf02ccfcc8531cb09f/maintainability)](https://codeclimate.com/github/DannyBen/runfile/maintainability)
8
7
 
9
8
  ---
@@ -20,9 +19,9 @@ to [Rake](https://github.com/ruby/rake), but with the full power of
20
19
  You create a `Runfile`, and execute commands with
21
20
  `run command arguments -and --flags`.
22
21
 
23
- ![Runfile Demo](https://raw.githubusercontent.com/DannyBen/runfile/master/demo.gif "Runfile Demo")
22
+ ![Runfile Demo](demo.svg "Runfile Demo")
24
23
 
25
- [Learn More in the Wiki](https://github.com/DannyBen/runfile/wiki)
24
+ [Learn More in the User Guide](https://runfile.dannyb.co)
26
25
 
27
26
  ---
28
27
 
@@ -114,13 +113,12 @@ When you execute `run`, we will look for files in this order:
114
113
  When you execute `run!`, we will ignore any local Runfile and only search
115
114
  for global (named) runfiles.
116
115
 
117
- Read more in the [Runfile Location and Filename wiki page](https://github.com/DannyBen/runfile/wiki/Runfile-Location-and-Filename)
116
+ Read more on [Runfile Location and Filename](https://runfile.dannyb.co/Runfile-Location-and-Filename)
118
117
 
119
118
 
120
119
  Documentation
121
120
  --------------------------------------------------
122
121
 
122
+ - [User Guide](https://runfile.dannyb.co)
123
123
  - [Learn by Example](https://github.com/DannyBen/runfile/tree/master/examples)
124
- - [Runfile Command Reference](https://github.com/DannyBen/runfile/wiki/Runfile-Command-Reference)
125
- - [Wiki](https://github.com/DannyBen/runfile/wiki)
126
124
  - [Rubydoc](http://www.rubydoc.info/gems/runfile)
@@ -22,6 +22,8 @@ module Runfile
22
22
  @summary = options.summary
23
23
  @actions = options.actions
24
24
  @options = options.options
25
+ @params = options.params
26
+ @env_vars = options.env_vars
25
27
  @examples = options.examples
26
28
  end
27
29
 
@@ -35,6 +37,8 @@ module Runfile
35
37
  doc += docopt_usage
36
38
  doc += docopt_commands width
37
39
  doc += docopt_options width
40
+ doc += docopt_params width
41
+ doc += docopt_env_vars width
38
42
  doc += docopt_examples width
39
43
  doc.join "\n"
40
44
  end
@@ -74,17 +78,17 @@ module Runfile
74
78
  @options['Options'] = {} unless @options['Options']
75
79
  @options['Options']['-h --help'] = 'Show this screen'
76
80
  @options['Options']['--version'] = 'Show version number' if @version
81
+ section_block @options, width
82
+ end
77
83
 
78
- doc = []
79
- @options.each do |scope, values|
80
- doc << "#{scope}:"
81
- values.each do |flag, text|
82
- helpline = " #{text}"
83
- wrapped = word_wrap helpline, width
84
- doc << " #{flag}\n#{wrapped}\n"
85
- end
86
- end
87
- doc
84
+ # Return all docopt params for 'Params' section
85
+ def docopt_params(width)
86
+ section_block @params, width
87
+ end
88
+
89
+ # Return all docopt params for 'Environment Variables' section
90
+ def docopt_env_vars(width)
91
+ section_block @env_vars, width
88
92
  end
89
93
 
90
94
  # Return all docopt lines for the 'Examples' section
@@ -101,6 +105,21 @@ module Runfile
101
105
  doc
102
106
  end
103
107
 
108
+ # Return a generic block containing scope section (e.g. "Options"),
109
+ # followed by key value paragraphs.
110
+ def section_block(definitions, width)
111
+ doc = []
112
+ definitions.each do |scope, values|
113
+ doc << "#{scope}:"
114
+ values.each do |label, text|
115
+ helpline = " #{text}"
116
+ wrapped = word_wrap helpline, width
117
+ doc << " #{label}\n#{wrapped}\n"
118
+ end
119
+ end
120
+ doc
121
+ end
122
+
104
123
  # Call the docopt handler, which will either return a parsed
105
124
  # arguments list, or halt execution and show usage.
106
125
  def args(argv)
@@ -43,6 +43,18 @@ module Runfile
43
43
  Runner.instance.add_option flag, text, scope
44
44
  end
45
45
 
46
+ # Add a parameter (can be called multiple times)
47
+ # param 'FOLDER', 'Folder to copy'
48
+ def param(name, text, scope=nil)
49
+ Runner.instance.add_param name, text, scope
50
+ end
51
+
52
+ # Set an environment variable (can be called multiple times)
53
+ # env_var 'USER', 'Set the user (same as --user)'
54
+ def env_var(name, text, scope = nil)
55
+ Runner.instance.add_env_var name, text, scope
56
+ end
57
+
46
58
  # Set an example command (can be called multiple times)
47
59
  # example 'server --background'
48
60
  def example(text)
@@ -73,28 +85,28 @@ module Runfile
73
85
 
74
86
  # Run a command, wait until it is done and continue
75
87
  # run 'rails server'
76
- def run(*args)
77
- ExecHandler.instance.run(*args)
88
+ def run(cmd)
89
+ ExecHandler.instance.run cmd
78
90
  end
79
91
 
80
92
  # Run a command, wait until it is done, then exit
81
93
  # run! 'rails server'
82
- def run!(*args)
83
- ExecHandler.instance.run!(*args)
94
+ def run!(cmd)
95
+ ExecHandler.instance.run! cmd
84
96
  end
85
97
 
86
98
  # Run a command in the background, optionally log to a log file and save
87
99
  # the process ID in a pid file
88
100
  # run_bg 'rails server', pid: 'rails', log: 'tmp/log.log'
89
- def run_bg(*args)
90
- ExecHandler.instance.run_bg(*args)
101
+ def run_bg(cmd, pid: nil, log: '/dev/null')
102
+ ExecHandler.instance.run_bg cmd, pid: pid, log: log
91
103
  end
92
104
 
93
105
  # Stop a command started with 'run_bg'. Provide the name of he pid file you
94
106
  # used in 'run_bg'
95
107
  # stop_bg 'rails'
96
- def stop_bg(*args)
97
- ExecHandler.instance.stop_bg(*args)
108
+ def stop_bg(pid)
109
+ ExecHandler.instance.stop_bg pid
98
110
  end
99
111
 
100
112
  # Set a block to be called before each run. The block should return
@@ -13,7 +13,8 @@ module Runfile
13
13
  include SettingsMixin
14
14
 
15
15
  attr_accessor :last_usage, :last_help, :name, :version,
16
- :summary, :namespace, :superspace, :actions, :examples, :options
16
+ :summary, :namespace, :superspace, :actions, :examples, :options,
17
+ :params, :env_vars
17
18
 
18
19
  # Initialize all variables to sensible defaults.
19
20
  def initialize
@@ -23,7 +24,9 @@ module Runfile
23
24
  @namespace = nil # dsl: command
24
25
  @actions = {} # dsl: action
25
26
  @options = {} # dsl: option
27
+ @params = {} # dsl: param
26
28
  @examples = [] # dsl: example
29
+ @env_vars = {} # dsl: env_var
27
30
  @name = "Runfile" # dsl: name
28
31
  @version = false # dsl: version
29
32
  @summary = false # dsl: summary
@@ -46,7 +49,7 @@ module Runfile
46
49
 
47
50
  # Add an action to the @actions array, and use the last known
48
51
  # usage and help messages sent by the DSL.
49
- def add_action(name, altname=nil, &block)
52
+ def add_action(name, altname = nil, &block)
50
53
  if @last_usage.nil?
51
54
  @last_usage = altname ? "(#{name}|#{altname})" : name
52
55
  end
@@ -66,12 +69,26 @@ module Runfile
66
69
  end
67
70
 
68
71
  # Add an option flag and its help text.
69
- def add_option(flag, text, scope=nil)
70
- scope or scope = 'Options'
72
+ def add_option(flag, text, scope = nil)
73
+ scope ||= 'Options'
71
74
  @options[scope] ||= {}
72
75
  @options[scope][flag] = text
73
76
  end
74
77
 
78
+ # Add a patameter and its help text.
79
+ def add_param(name, text, scope = nil)
80
+ scope ||= 'Parameters'
81
+ @params[scope] ||= {}
82
+ @params[scope][name] = text
83
+ end
84
+
85
+ # Add env_var command.
86
+ def add_env_var(name, text, scope = nil)
87
+ scope ||= 'Environment Variables'
88
+ @env_vars[scope] ||= {}
89
+ @env_vars[scope][name] = text
90
+ end
91
+
75
92
  # Add example command.
76
93
  def add_example(command)
77
94
  @examples << (@namespace ? "#{@namespace} #{command}" : command)
@@ -85,7 +102,7 @@ module Runfile
85
102
  docopt_exec argv
86
103
  rescue Docopt::Exit => ex
87
104
  puts ex.message
88
- exit 1
105
+ exit 2
89
106
  end
90
107
  end
91
108
 
@@ -144,11 +161,12 @@ module Runfile
144
161
  maker = RunfileHelper.new
145
162
  maker.purge_settings if @ignore_settings
146
163
  runfile = maker.handle argv
147
- if runfile
148
- @superspace = argv[0]
149
- execute argv, runfile
150
- end
151
- exit 1
164
+
165
+ exit 3 unless runfile
166
+
167
+ @superspace = argv[0]
168
+ execute argv, runfile
169
+ exit
152
170
  end
153
171
 
154
172
  def expand_shortcuts(argv)
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = "0.10.2"
2
+ VERSION = "0.11.2"
3
3
  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: 0.10.2
4
+ version: 0.11.2
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: 2018-10-03 00:00:00.000000000 Z
11
+ date: 2020-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -84,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubyforge_project:
88
- rubygems_version: 2.7.6
87
+ rubygems_version: 3.1.4
89
88
  signing_key:
90
89
  specification_version: 4
91
90
  summary: If Rake and Docopt had a baby