runfile 0.1.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/run +6 -0
- data/lib/runfile.rb +5 -0
- data/lib/runfile/action.rb +15 -0
- data/lib/runfile/docopt_maker.rb +43 -0
- data/lib/runfile/dsl.rb +25 -0
- data/lib/runfile/runner.rb +58 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 140227a208cb696ecea61be2900adaa55a2e57c4
|
4
|
+
data.tar.gz: a8ebcc1b213d108fdb90661b586364860e6dbea3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8fc91d59ced071ec86d3bb156937b7f321872fc50f52a3269adfdc4d3227d4d086e05e187140bb397bab920fe326e6c69ce42a19f1dc7a88fed4ec58d4515e6
|
7
|
+
data.tar.gz: 1e42a00ceea31aa897dcc4905e137b2d9c24dcfcb015735c3000c43b5892835c4f1ec2d6204b676566d6cea7a292e8da2795f71cc2a93d80488f5d3a0c732b97
|
data/bin/run
ADDED
data/lib/runfile.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'docopt'
|
2
|
+
require 'colsole'
|
3
|
+
|
4
|
+
module Runfile
|
5
|
+
include Colsole
|
6
|
+
class DocoptMaker
|
7
|
+
def initialize(version, summary, actions, options)
|
8
|
+
@version = version
|
9
|
+
@summary = summary
|
10
|
+
@actions = actions
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def make
|
15
|
+
width, height = detect_terminal_size
|
16
|
+
doc = "Runfile #{@version}\n"
|
17
|
+
doc += "#{@summary} \n" if @summary
|
18
|
+
doc += "\nUsage:\n";
|
19
|
+
@actions.each do |name, action|
|
20
|
+
doc += " run #{action.usage}\n"
|
21
|
+
end
|
22
|
+
doc += " run (-h | --help | --version)\n\n"
|
23
|
+
caption_printed = false
|
24
|
+
@actions.each do |name, action|
|
25
|
+
action.help or next
|
26
|
+
doc += "Commands:\n" unless caption_printed
|
27
|
+
caption_printed = true
|
28
|
+
helpline = " #{action.help}"
|
29
|
+
wrapped = word_wrap helpline, width
|
30
|
+
doc += " #{action.usage}\n#{wrapped}\n\n"
|
31
|
+
end
|
32
|
+
doc += "Options:\n"
|
33
|
+
doc += " -h --help\n Show this screen\n\n"
|
34
|
+
doc += " --version\n Show version\n\n"
|
35
|
+
@options.each do |flag, text|
|
36
|
+
helpline = " #{text}"
|
37
|
+
wrapped = word_wrap helpline, width
|
38
|
+
doc += " #{flag}\n#{wrapped}\n\n"
|
39
|
+
end
|
40
|
+
doc
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/runfile/dsl.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Runfile
|
2
|
+
def version(ver)
|
3
|
+
Runner.instance.version = ver
|
4
|
+
end
|
5
|
+
|
6
|
+
def usage(text)
|
7
|
+
Runner.instance.last_usage = text
|
8
|
+
end
|
9
|
+
|
10
|
+
def help(text)
|
11
|
+
Runner.instance.last_help = text
|
12
|
+
end
|
13
|
+
|
14
|
+
def action(name, &block)
|
15
|
+
Runner.instance.add_action name, &block
|
16
|
+
end
|
17
|
+
|
18
|
+
def summary(text)
|
19
|
+
Runner.instance.summary = text
|
20
|
+
end
|
21
|
+
|
22
|
+
def option(flag, text)
|
23
|
+
Runner.instance.add_option flag, text
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'docopt'
|
2
|
+
|
3
|
+
module Runfile
|
4
|
+
class Runner
|
5
|
+
attr_writer :last_usage, :last_help, :version, :summary
|
6
|
+
|
7
|
+
@@instance = nil
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@last_usage = nil
|
11
|
+
@last_help = nil
|
12
|
+
@actions = {}
|
13
|
+
@options = {}
|
14
|
+
@version = "0.0.0"
|
15
|
+
@summary = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.instance
|
19
|
+
@@instance = self.new if @@instance.nil?
|
20
|
+
@@instance
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute(argv)
|
24
|
+
File.exist? 'Runfile' or abort "Runfile not found"
|
25
|
+
load 'Runfile'
|
26
|
+
@@instance.run *argv
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_action(name, &block)
|
30
|
+
@actions[name] = Action.new(block, @last_usage, @last_help)
|
31
|
+
@last_usage = nil
|
32
|
+
@last_help = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_option(flag, text)
|
36
|
+
@options[flag] = text
|
37
|
+
end
|
38
|
+
|
39
|
+
def run(*argv)
|
40
|
+
action = argv[0]
|
41
|
+
action and action = action.to_sym
|
42
|
+
begin
|
43
|
+
args = Docopt::docopt(docopt, version: @version, argv:argv)
|
44
|
+
@actions.has_key? action or abort "Runfile error: Action :#{action} is not defined"
|
45
|
+
@actions[action].execute args
|
46
|
+
rescue Docopt::Exit => e
|
47
|
+
puts e.message
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def docopt
|
54
|
+
maker = DocoptMaker.new(@version, @summary, @actions, @options)
|
55
|
+
maker.make
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: runfile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Ben Shitrit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: docopt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.5'
|
41
|
+
description: An easy way to create project specific command line utilities
|
42
|
+
email: db@dannyben.com
|
43
|
+
executables:
|
44
|
+
- run
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- bin/run
|
49
|
+
- lib/runfile.rb
|
50
|
+
- lib/runfile/action.rb
|
51
|
+
- lib/runfile/docopt_maker.rb
|
52
|
+
- lib/runfile/dsl.rb
|
53
|
+
- lib/runfile/runner.rb
|
54
|
+
homepage: http://sector-seven.net
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.3.1
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.6
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: If Rake and Docopt had a baby
|
78
|
+
test_files: []
|
79
|
+
has_rdoc:
|