runfile 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -52
- data/bin/run +0 -1
- data/bin/run! +0 -1
- data/lib/runfile/{exec.rb → compatibility.rb} +18 -10
- data/lib/runfile/docopt_helper.rb +12 -6
- data/lib/runfile/dsl.rb +6 -45
- data/lib/runfile/refinements.rb +22 -0
- data/lib/runfile/runfile_helper.rb +14 -13
- data/lib/runfile/runner.rb +14 -7
- data/lib/runfile/templates/Runfile +7 -5
- data/lib/runfile/terminal.rb +32 -0
- data/lib/runfile/version.rb +1 -1
- data/lib/runfile.rb +2 -3
- metadata +7 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79a1c61423d09207b687d93f98035c5ca6b5e9d36f7b4acc12d93ccaa817c873
|
4
|
+
data.tar.gz: 0d870a0f93a9add25113e8030a02ce99dd2ecb0ed8f42d5eddb69b520b998da0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 387383e744bac9dbd8ab89598df2a3217a4fa58f120b60ab7c31bbbfec074ae3fee0512cdee002b740af3aa85a6cd930ddfeefbe1d14deec182ebf77d57c8ab6
|
7
|
+
data.tar.gz: ca1b2962b157454842a0050cd3bf70826509362e7b18b9ebd2c1cc863480b0ac7f7556ad9e4fed27bad22b9c11238cf6b063e57e8b1d0459607fdb791c4ea1ae
|
data/README.md
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
<div align='center'>
|
2
|
+
<img src='logo.svg' width=280>
|
3
|
+
|
4
|
+
# Runfile - command line for your projects
|
3
5
|
|
4
6
|
[![Gem Version](https://badge.fury.io/rb/runfile.svg)](https://badge.fury.io/rb/runfile)
|
5
|
-
[![Build Status](https://
|
6
|
-
[![BCH compliance](https://bettercodehub.com/edge/badge/DannyBen/runfile?branch=master)](https://bettercodehub.com/results/DannyBen/runfile)
|
7
|
+
[![Build Status](https://github.com/DannyBen/runfile/workflows/Test/badge.svg)](https://github.com/DannyBen/runfile/actions?query=workflow%3ATest)
|
7
8
|
[![Maintainability](https://api.codeclimate.com/v1/badges/81cf02ccfcc8531cb09f/maintainability)](https://codeclimate.com/github/DannyBen/runfile/maintainability)
|
8
9
|
|
9
10
|
---
|
10
11
|
|
11
|
-
A beautiful command line application framework
|
12
|
-
Rake-inspired
|
12
|
+
A beautiful command line application framework
|
13
|
+
Rake-inspired - Docopt inside
|
13
14
|
|
14
15
|
---
|
15
16
|
|
17
|
+
</div>
|
18
|
+
|
16
19
|
**Runfile** lets you create command line applications in a way similar
|
17
20
|
to [Rake](https://github.com/ruby/rake), but with the full power of
|
18
21
|
[Docopt](http://docopt.org/) command line options.
|
@@ -20,28 +23,9 @@ to [Rake](https://github.com/ruby/rake), but with the full power of
|
|
20
23
|
You create a `Runfile`, and execute commands with
|
21
24
|
`run command arguments -and --flags`.
|
22
25
|
|
23
|
-
![Runfile Demo](
|
24
|
-
|
25
|
-
[Learn More in the Wiki](https://github.com/DannyBen/runfile/wiki)
|
26
|
-
|
27
|
-
---
|
28
|
-
|
29
|
-
**Upgrade Notice:**
|
30
|
-
If you are upgrading to 0.9.x - the `name` command was replaced
|
31
|
-
with `title`.
|
32
|
-
|
33
|
-
---
|
34
|
-
|
35
|
-
Install
|
36
|
-
--------------------------------------------------
|
37
|
-
|
38
|
-
```shell
|
39
|
-
$ gem install runfile
|
40
|
-
```
|
41
|
-
|
26
|
+
![Runfile Demo](demo.svg "Runfile Demo")
|
42
27
|
|
43
|
-
Quick Start
|
44
|
-
--------------------------------------------------
|
28
|
+
## Quick Start
|
45
29
|
|
46
30
|
```shell
|
47
31
|
$ run new # create a new Runfile
|
@@ -50,8 +34,7 @@ $ vi Runfile # edit the Runfile
|
|
50
34
|
```
|
51
35
|
|
52
36
|
|
53
|
-
Example
|
54
|
-
--------------------------------------------------
|
37
|
+
## Example
|
55
38
|
|
56
39
|
The most minimal `Runfile` looks like this:
|
57
40
|
|
@@ -64,14 +47,14 @@ end
|
|
64
47
|
|
65
48
|
You can then run it by executing this command:
|
66
49
|
|
67
|
-
```
|
50
|
+
```shell
|
68
51
|
$ run greet Luke
|
69
52
|
Hello Luke
|
70
53
|
```
|
71
54
|
|
72
55
|
Executing `run` without parameters, will show the usage patterns:
|
73
56
|
|
74
|
-
```
|
57
|
+
```shell
|
75
58
|
$ run
|
76
59
|
Usage:
|
77
60
|
run greet <name>
|
@@ -80,7 +63,7 @@ Usage:
|
|
80
63
|
|
81
64
|
Executing `run --help` will show the full help document (docopt)
|
82
65
|
|
83
|
-
```
|
66
|
+
```shell
|
84
67
|
$ run --help
|
85
68
|
Runfile 0.0.0
|
86
69
|
|
@@ -96,31 +79,26 @@ Options:
|
|
96
79
|
Show version
|
97
80
|
```
|
98
81
|
|
82
|
+
## Documentation
|
99
83
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
In addition to the per project `Runfile` files, it is also possible to
|
104
|
-
create global runfiles that are accessible to you only or to anybody on
|
105
|
-
the system.
|
84
|
+
- [User Guide](https://runfile.dannyb.co/)
|
85
|
+
- [Learn by Example](https://github.com/DannyBen/runfile/tree/master/examples#readme)
|
106
86
|
|
107
|
-
|
87
|
+
## Breaking changes in 0.12.0
|
108
88
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
89
|
+
Note that version 0.12.0 removes several commands from the DSL.
|
90
|
+
If you were using any of the Colsole commands (`say`, `resay`, etc.), or any of
|
91
|
+
the `run`, `run_bg` commands, you will have to adjust your Runfile since they are
|
92
|
+
no longer available.
|
113
93
|
|
114
|
-
|
115
|
-
|
94
|
+
For convenience, you can simply `require runfile/compatibility` at the top of
|
95
|
+
your Runfile, to still have this functionality included.
|
116
96
|
|
117
|
-
|
97
|
+
More info and alternative solutions in
|
98
|
+
[this pull request](https://github.com/DannyBen/runfile/pull/46).
|
118
99
|
|
100
|
+
## Contributing / Support
|
119
101
|
|
120
|
-
|
121
|
-
|
102
|
+
If you experience any issue, have a question or a suggestion, or if you wish
|
103
|
+
to contribute, feel free to [open an issue](https://github.com/DannyBen/runfile/issues).
|
122
104
|
|
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
|
-
- [Rubydoc](http://www.rubydoc.info/gems/runfile)
|
data/bin/run
CHANGED
data/bin/run!
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
-
|
1
|
+
# This file provides a compatibility layer for version 0.12.0 so that
|
2
|
+
# all the Colsole methods (say, resay...) and ExecHandler methods
|
3
|
+
# (run, run_bg...) are still available
|
4
|
+
# Simply require 'runfile/compatibility' to have the same functionality
|
5
|
+
# as older versions.
|
6
|
+
#
|
7
|
+
# Notes:
|
8
|
+
# - You need to have the colsole gem installed
|
9
|
+
# - Requiring this file also includes it (see the end of the file).
|
10
|
+
# - This functinality will be removed in future versions
|
11
|
+
# - More info: https://github.com/DannyBen/runfile/pull/46
|
12
|
+
require 'colsole'
|
2
13
|
|
3
14
|
module Runfile
|
4
|
-
|
5
|
-
|
6
|
-
# through a Runfile action.
|
7
|
-
# It is mainly a convenient wrapper around `system` and `exec` and it also
|
8
|
-
# adds functions for running background tasks with ease.
|
9
|
-
class ExecHandler
|
10
|
-
include Singleton
|
15
|
+
module Compatibilty
|
16
|
+
include Colsole
|
11
17
|
|
12
18
|
# Run a command, wait until it is done and continue
|
13
19
|
def run(cmd)
|
@@ -62,7 +68,7 @@ module Runfile
|
|
62
68
|
@after_run_block = block
|
63
69
|
end
|
64
70
|
|
65
|
-
|
71
|
+
private
|
66
72
|
|
67
73
|
def pid_dir
|
68
74
|
defined?(Runfile.pid_dir) ? Runfile.pid_dir : nil
|
@@ -73,4 +79,6 @@ module Runfile
|
|
73
79
|
end
|
74
80
|
|
75
81
|
end
|
76
|
-
end
|
82
|
+
end
|
83
|
+
|
84
|
+
include Runfile::Compatibilty
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'docopt'
|
2
|
-
require 'colsole'
|
3
2
|
|
4
3
|
module Runfile
|
5
4
|
# The DocoptHelper class handles the dynamic generation of the
|
@@ -7,7 +6,7 @@ module Runfile
|
|
7
6
|
# to call Docopt so it returns the parsed arguments or halts with
|
8
7
|
# usage message).
|
9
8
|
class DocoptHelper
|
10
|
-
|
9
|
+
using Refinements
|
11
10
|
|
12
11
|
# The constructor expects to an object that responds to all the
|
13
12
|
# textual details needed to generate a docopt document (name, version,
|
@@ -23,13 +22,14 @@ module Runfile
|
|
23
22
|
@actions = options.actions
|
24
23
|
@options = options.options
|
25
24
|
@params = options.params
|
25
|
+
@env_vars = options.env_vars
|
26
26
|
@examples = options.examples
|
27
27
|
end
|
28
28
|
|
29
29
|
# Generate a document based on all the actions, help messages
|
30
30
|
# and options we have collected from the Runfile DSL.
|
31
31
|
def docopt
|
32
|
-
width =
|
32
|
+
width = Terminal.width
|
33
33
|
doc = []
|
34
34
|
doc << (@version ? "#{@name} #{@version}" : "#{@name}")
|
35
35
|
doc << "#{@summary}" if @summary
|
@@ -37,6 +37,7 @@ module Runfile
|
|
37
37
|
doc += docopt_commands width
|
38
38
|
doc += docopt_options width
|
39
39
|
doc += docopt_params width
|
40
|
+
doc += docopt_env_vars width
|
40
41
|
doc += docopt_examples width
|
41
42
|
doc.join "\n"
|
42
43
|
end
|
@@ -65,7 +66,7 @@ module Runfile
|
|
65
66
|
doc << "Commands:" unless caption_printed
|
66
67
|
caption_printed = true
|
67
68
|
helpline = " #{action.help}"
|
68
|
-
wrapped = word_wrap
|
69
|
+
wrapped = helpline.word_wrap width
|
69
70
|
doc << " #{action.usage}\n#{wrapped}\n" unless action.usage == false
|
70
71
|
end
|
71
72
|
doc
|
@@ -84,6 +85,11 @@ module Runfile
|
|
84
85
|
section_block @params, width
|
85
86
|
end
|
86
87
|
|
88
|
+
# Return all docopt params for 'Environment Variables' section
|
89
|
+
def docopt_env_vars(width)
|
90
|
+
section_block @env_vars, width
|
91
|
+
end
|
92
|
+
|
87
93
|
# Return all docopt lines for the 'Examples' section
|
88
94
|
def docopt_examples(width)
|
89
95
|
return [] if @examples.empty?
|
@@ -92,7 +98,7 @@ module Runfile
|
|
92
98
|
base_command = @superspace ? "run #{@superspace}" : "run"
|
93
99
|
@examples.each do |command|
|
94
100
|
helpline = " #{base_command} #{command}"
|
95
|
-
wrapped = word_wrap
|
101
|
+
wrapped = helpline.word_wrap width
|
96
102
|
doc << "#{wrapped}"
|
97
103
|
end
|
98
104
|
doc
|
@@ -106,7 +112,7 @@ module Runfile
|
|
106
112
|
doc << "#{scope}:"
|
107
113
|
values.each do |label, text|
|
108
114
|
helpline = " #{text}"
|
109
|
-
wrapped = word_wrap
|
115
|
+
wrapped = helpline.word_wrap width
|
110
116
|
doc << " #{label}\n#{wrapped}\n"
|
111
117
|
end
|
112
118
|
end
|
data/lib/runfile/dsl.rb
CHANGED
@@ -49,6 +49,12 @@ module Runfile
|
|
49
49
|
Runner.instance.add_param name, text, scope
|
50
50
|
end
|
51
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
|
+
|
52
58
|
# Set an example command (can be called multiple times)
|
53
59
|
# example 'server --background'
|
54
60
|
def example(text)
|
@@ -77,51 +83,6 @@ module Runfile
|
|
77
83
|
Runner.instance.cross_call command_string
|
78
84
|
end
|
79
85
|
|
80
|
-
# Run a command, wait until it is done and continue
|
81
|
-
# run 'rails server'
|
82
|
-
def run(*args)
|
83
|
-
ExecHandler.instance.run(*args)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Run a command, wait until it is done, then exit
|
87
|
-
# run! 'rails server'
|
88
|
-
def run!(*args)
|
89
|
-
ExecHandler.instance.run!(*args)
|
90
|
-
end
|
91
|
-
|
92
|
-
# Run a command in the background, optionally log to a log file and save
|
93
|
-
# the process ID in a pid file
|
94
|
-
# run_bg 'rails server', pid: 'rails', log: 'tmp/log.log'
|
95
|
-
def run_bg(*args)
|
96
|
-
ExecHandler.instance.run_bg(*args)
|
97
|
-
end
|
98
|
-
|
99
|
-
# Stop a command started with 'run_bg'. Provide the name of he pid file you
|
100
|
-
# used in 'run_bg'
|
101
|
-
# stop_bg 'rails'
|
102
|
-
def stop_bg(*args)
|
103
|
-
ExecHandler.instance.stop_bg(*args)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Set a block to be called before each run. The block should return
|
107
|
-
# the command to run, since this is intended to let the block modify
|
108
|
-
# the command if it needs to.
|
109
|
-
# before_run do |command|
|
110
|
-
# puts "BEFORE #{command}"
|
111
|
-
# command
|
112
|
-
# end
|
113
|
-
def before_run(&block)
|
114
|
-
ExecHandler.instance.before_run(&block)
|
115
|
-
end
|
116
|
-
|
117
|
-
# Set a block to be called after each run
|
118
|
-
# before_run do |command|
|
119
|
-
# puts "AFTER #{command}"
|
120
|
-
# end
|
121
|
-
def after_run(&block)
|
122
|
-
ExecHandler.instance.after_run(&block)
|
123
|
-
end
|
124
|
-
|
125
86
|
# Also allow to use 'endcommand' instead of 'command' to end
|
126
87
|
# a command namespace definition
|
127
88
|
alias_method :endcommand, :command
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Runfile
|
2
|
+
module Refinements
|
3
|
+
refine String do
|
4
|
+
def word_wrap(length = nil)
|
5
|
+
text = self
|
6
|
+
|
7
|
+
length ||= Terminal.width
|
8
|
+
lead = text[/^\s*/]
|
9
|
+
text.strip!
|
10
|
+
length -= lead.length
|
11
|
+
text.split("\n").collect! do |line|
|
12
|
+
if line.length > length
|
13
|
+
line.gsub!(/([^\s]{#{length}})([^\s$])/, "\\1 \\2")
|
14
|
+
line.gsub(/(.{1,#{length}})(\s+|$)/, "#{lead}\\1\n").rstrip
|
15
|
+
else
|
16
|
+
"#{lead}#{line}"
|
17
|
+
end
|
18
|
+
end * "\n"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -8,6 +8,7 @@ module Runfile
|
|
8
8
|
# 2. Creating new runfiles (`run new`)
|
9
9
|
# 3. Showing a list of found system runfiles in a colorful help
|
10
10
|
class RunfileHelper
|
11
|
+
using Refinements
|
11
12
|
include SettingsMixin
|
12
13
|
|
13
14
|
# Handle the case when `run` is called without a Runfile
|
@@ -72,14 +73,14 @@ module Runfile
|
|
72
73
|
|
73
74
|
# Show some helpful tips, and a list of available runfiles
|
74
75
|
def show_make_help(runfiles, compact=false)
|
75
|
-
|
76
|
+
puts "Runfile engine v#{Runfile::VERSION}" unless compact
|
76
77
|
if runfiles.size < 3 and !compact
|
77
|
-
|
78
|
+
puts "\nTip: Type 'run new' or 'run new name' to create a runfile.\nFor global access, place named.runfiles in ~/runfile/ or in /etc/runfile/."
|
78
79
|
end
|
79
80
|
if runfiles.empty?
|
80
|
-
|
81
|
+
puts "\nRunfile not found."
|
81
82
|
else
|
82
|
-
|
83
|
+
puts ""
|
83
84
|
compact ? say_runfile_usage(runfiles) : say_runfile_list(runfiles)
|
84
85
|
end
|
85
86
|
end
|
@@ -110,14 +111,14 @@ module Runfile
|
|
110
111
|
def say_runfile_list(runfiles)
|
111
112
|
runfile_paths = runfiles.map { |f| File.dirname f }
|
112
113
|
max = runfile_paths.max_by(&:length).size
|
113
|
-
width =
|
114
|
+
width = Terminal.width
|
114
115
|
runfiles.each do |f|
|
115
116
|
f[/([^\/]+).runfile$/]
|
116
117
|
command = "run #{$1}"
|
117
118
|
spacer_size = width - max - command.size - 6
|
118
119
|
spacer_size = [1, spacer_size].max
|
119
120
|
spacer = '.' * spacer_size
|
120
|
-
|
121
|
+
puts " #{command} #{spacer} #{File.dirname f}"
|
121
122
|
end
|
122
123
|
end
|
123
124
|
|
@@ -125,19 +126,19 @@ module Runfile
|
|
125
126
|
def say_runfile_usage(runfiles)
|
126
127
|
runfiles_as_columns = get_runfiles_as_columns runfiles
|
127
128
|
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
puts "#{settings.intro}\n" if settings.intro
|
130
|
+
puts "Usage: run <file>"
|
131
|
+
puts runfiles_as_columns
|
131
132
|
|
132
133
|
show_shortcuts if settings.shortcuts
|
133
134
|
end
|
134
135
|
|
135
136
|
# Prints a friendly output of the shortcut list
|
136
137
|
def show_shortcuts
|
137
|
-
|
138
|
+
puts "\nShortcuts:"
|
138
139
|
max = settings.shortcuts.keys.max_by(&:length).length
|
139
140
|
settings.shortcuts.each_pair do |shortcut, command|
|
140
|
-
|
141
|
+
puts " #{shortcut.rjust max} : #{command}"
|
141
142
|
end
|
142
143
|
end
|
143
144
|
|
@@ -145,10 +146,10 @@ module Runfile
|
|
145
146
|
# current terminal width
|
146
147
|
def get_runfiles_as_columns(runfiles)
|
147
148
|
namelist = runfile_names runfiles
|
148
|
-
width =
|
149
|
+
width = Terminal.width
|
149
150
|
max = namelist.max_by(&:length).length
|
150
151
|
message = " " + namelist.map {|f| f.ljust max+1 }.join(' ')
|
151
|
-
word_wrap
|
152
|
+
message.word_wrap width
|
152
153
|
end
|
153
154
|
|
154
155
|
def runfile_names(runfiles)
|
data/lib/runfile/runner.rb
CHANGED
@@ -14,7 +14,7 @@ module Runfile
|
|
14
14
|
|
15
15
|
attr_accessor :last_usage, :last_help, :name, :version,
|
16
16
|
:summary, :namespace, :superspace, :actions, :examples, :options,
|
17
|
-
:params
|
17
|
+
:params, :env_vars
|
18
18
|
|
19
19
|
# Initialize all variables to sensible defaults.
|
20
20
|
def initialize
|
@@ -26,6 +26,7 @@ module Runfile
|
|
26
26
|
@options = {} # dsl: option
|
27
27
|
@params = {} # dsl: param
|
28
28
|
@examples = [] # dsl: example
|
29
|
+
@env_vars = {} # dsl: env_var
|
29
30
|
@name = "Runfile" # dsl: name
|
30
31
|
@version = false # dsl: version
|
31
32
|
@summary = false # dsl: summary
|
@@ -48,7 +49,7 @@ module Runfile
|
|
48
49
|
|
49
50
|
# Add an action to the @actions array, and use the last known
|
50
51
|
# usage and help messages sent by the DSL.
|
51
|
-
def add_action(name, altname=nil, &block)
|
52
|
+
def add_action(name, altname = nil, &block)
|
52
53
|
if @last_usage.nil?
|
53
54
|
@last_usage = altname ? "(#{name}|#{altname})" : name
|
54
55
|
end
|
@@ -68,19 +69,26 @@ module Runfile
|
|
68
69
|
end
|
69
70
|
|
70
71
|
# Add an option flag and its help text.
|
71
|
-
def add_option(flag, text, scope=nil)
|
72
|
-
scope
|
72
|
+
def add_option(flag, text, scope = nil)
|
73
|
+
scope ||= 'Options'
|
73
74
|
@options[scope] ||= {}
|
74
75
|
@options[scope][flag] = text
|
75
76
|
end
|
76
77
|
|
77
78
|
# Add a patameter and its help text.
|
78
|
-
def add_param(name, text, scope=nil)
|
79
|
-
scope
|
79
|
+
def add_param(name, text, scope = nil)
|
80
|
+
scope ||= 'Parameters'
|
80
81
|
@params[scope] ||= {}
|
81
82
|
@params[scope][name] = text
|
82
83
|
end
|
83
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
|
+
|
84
92
|
# Add example command.
|
85
93
|
def add_example(command)
|
86
94
|
@examples << (@namespace ? "#{@namespace} #{command}" : command)
|
@@ -166,7 +174,6 @@ module Runfile
|
|
166
174
|
if settings.shortcuts and settings.shortcuts[possible_candidate]
|
167
175
|
shortcut_value = settings.shortcuts[argv[0]]
|
168
176
|
expanded = shortcut_value.split ' '
|
169
|
-
say "!txtblu!# #{possible_candidate} > #{shortcut_value}"
|
170
177
|
argv.shift
|
171
178
|
argv = expanded + argv
|
172
179
|
end
|
@@ -2,13 +2,15 @@ title "Greeter"
|
|
2
2
|
summary "A sample Runfile"
|
3
3
|
version "0.1.0"
|
4
4
|
|
5
|
-
usage "hello [<name> --
|
5
|
+
usage "hello [<name> --shout]"
|
6
6
|
help "Say hello"
|
7
|
-
option "-
|
7
|
+
option "-s --shout", "Greet louder"
|
8
8
|
action :hello do |args|
|
9
|
-
|
10
|
-
|
9
|
+
message = "Hello #{args['<name>']}"
|
10
|
+
|
11
|
+
if args['--shout']
|
12
|
+
puts message.upcase
|
11
13
|
else
|
12
|
-
|
14
|
+
puts message
|
13
15
|
end
|
14
16
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file provides some terminal related utilities (extracted from Colsole)
|
2
|
+
|
3
|
+
module Runfile
|
4
|
+
class Terminal
|
5
|
+
class << self
|
6
|
+
def size(default = [80,30])
|
7
|
+
if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
|
8
|
+
result = [ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
|
9
|
+
elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && command_exist?('tput')
|
10
|
+
result = [`tput cols 2>&1`.to_i, `tput lines 2>&1`.to_i]
|
11
|
+
elsif STDIN.tty? && command_exist?('stty')
|
12
|
+
result = `stty size 2>&1`.scan(/\d+/).map { |s| s.to_i }.reverse
|
13
|
+
else
|
14
|
+
result = default
|
15
|
+
end
|
16
|
+
result = default unless result[0].is_a? Integer and result[1].is_a? Integer and result[0] > 0 and result[1] > 0
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
def width
|
21
|
+
size[0]
|
22
|
+
end
|
23
|
+
|
24
|
+
def command_exist?(command)
|
25
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir|
|
26
|
+
File.exist?(File.join dir, command) or File.exist?(File.join dir, "#{command}.exe")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/runfile/version.rb
CHANGED
data/lib/runfile.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'runfile/version'
|
2
|
+
require 'runfile/terminal'
|
3
|
+
require 'runfile/refinements'
|
2
4
|
require 'runfile/settings'
|
3
5
|
require 'runfile/setup'
|
4
6
|
require 'runfile/docopt_helper'
|
@@ -6,6 +8,3 @@ require 'runfile/runfile_helper'
|
|
6
8
|
require 'runfile/action'
|
7
9
|
require 'runfile/runner'
|
8
10
|
require 'runfile/dsl'
|
9
|
-
require 'runfile/exec'
|
10
|
-
|
11
|
-
require 'byebug' if ENV['BYEBUG']
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
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:
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: colsole
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.5'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.5'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: docopt
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,14 +38,16 @@ files:
|
|
52
38
|
- bin/run!
|
53
39
|
- lib/runfile.rb
|
54
40
|
- lib/runfile/action.rb
|
41
|
+
- lib/runfile/compatibility.rb
|
55
42
|
- lib/runfile/docopt_helper.rb
|
56
43
|
- lib/runfile/dsl.rb
|
57
|
-
- lib/runfile/
|
44
|
+
- lib/runfile/refinements.rb
|
58
45
|
- lib/runfile/runfile_helper.rb
|
59
46
|
- lib/runfile/runner.rb
|
60
47
|
- lib/runfile/settings.rb
|
61
48
|
- lib/runfile/setup.rb
|
62
49
|
- lib/runfile/templates/Runfile
|
50
|
+
- lib/runfile/terminal.rb
|
63
51
|
- lib/runfile/version.rb
|
64
52
|
homepage: https://github.com/DannyBen/runfile
|
65
53
|
licenses:
|
@@ -77,15 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
65
|
requirements:
|
78
66
|
- - ">="
|
79
67
|
- !ruby/object:Gem::Version
|
80
|
-
version: 2.
|
68
|
+
version: 2.4.0
|
81
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
70
|
requirements:
|
83
71
|
- - ">="
|
84
72
|
- !ruby/object:Gem::Version
|
85
73
|
version: '0'
|
86
74
|
requirements: []
|
87
|
-
|
88
|
-
rubygems_version: 2.7.6
|
75
|
+
rubygems_version: 3.2.25
|
89
76
|
signing_key:
|
90
77
|
specification_version: 4
|
91
78
|
summary: If Rake and Docopt had a baby
|