dramaturg 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +20 -0
- data/Rakefile +2 -0
- data/dramaturg.gemspec +35 -0
- data/examples/git_feature_branch.rb +24 -0
- data/examples/just_print.rb +19 -0
- data/lib/dramaturg/command/hash_like.rb +42 -0
- data/lib/dramaturg/command/opt.rb +27 -0
- data/lib/dramaturg/command/parser.rb +34 -0
- data/lib/dramaturg/command.rb +40 -0
- data/lib/dramaturg/ctrl_c_handler/skip.rb +10 -0
- data/lib/dramaturg/ctrl_c_handler/skip_or_exit.rb +19 -0
- data/lib/dramaturg/ctrl_c_handler.rb +8 -0
- data/lib/dramaturg/prompter/base.rb +34 -0
- data/lib/dramaturg/prompter/madCLIbs.rb +57 -0
- data/lib/dramaturg/prompter/use_defaults.rb +38 -0
- data/lib/dramaturg/prompter.rb +6 -0
- data/lib/dramaturg/runner/base.rb +36 -0
- data/lib/dramaturg/runner/print.rb +17 -0
- data/lib/dramaturg/runner/shell.rb +18 -0
- data/lib/dramaturg/runner.rb +8 -0
- data/lib/dramaturg/script.rb +77 -0
- data/lib/dramaturg/value/default.rb +11 -0
- data/lib/dramaturg/value/fixed.rb +4 -0
- data/lib/dramaturg/value.rb +8 -0
- data/lib/dramaturg/version.rb +3 -0
- data/lib/dramaturg.rb +13 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e353b44eaeebb604d4445bfa5a91f8d4867d2da6
|
4
|
+
data.tar.gz: 3ca57c447212cd023858c8c68c7f3d40d2599ce6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa8c32f4f351075b5c94cae0e9348849fa570a25f7cacb9b9a1e58f977f2067dd452587f971d132f07c6f4e4d1f98829f7fdab173fc1c3190a1189f9d16c3c62
|
7
|
+
data.tar.gz: 12895780db2b689eab7c06c5777c894b75cd5d951c47046aaaf4fbd5b29a17bd847c5d1fe09eecbc6b75d7246450014d3368d1603825ce109941828437688361
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Donald Guy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Dramaturg: Optionally-interactive shell scripts
|
2
|
+
|
3
|
+
In theater, a dramaturg (or "literary manager") is a behind-the-scenes individual who researches and advises in the development of dramatic scripts and productions.
|
4
|
+
|
5
|
+
This library hopes to allow you to fulfill a similar role, but for shell scripts and cli workflows.
|
6
|
+
|
7
|
+
In particular, in the spirit of devops and "learn by doing", it seeks to empower those in-the-know (e.g. ops-types or senior developers) to deliver a workflow to those-less-so (e.g. junior developers) that can be executed outright—or easily departed from as desired & appropriate for the user's level of familiarity with the tools & proccess.
|
8
|
+
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
See [`./examples`](https://github.com/donaldguy/dramaturg/tree/master/examples) for example code
|
13
|
+
|
14
|
+
## Contributing
|
15
|
+
|
16
|
+
1. Fork it ( https://github.com/donaldguy/dramaturg/fork )
|
17
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
18
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
19
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
20
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/dramaturg.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dramaturg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dramaturg"
|
8
|
+
spec.version = Dramaturg::VERSION
|
9
|
+
spec.authors = ["Donald Guy"]
|
10
|
+
spec.email = ["fawkes@mit.edu"]
|
11
|
+
spec.summary = %q{A framework for optionally-interactive shell scripts}
|
12
|
+
spec.description = %q{In theater, a dramaturg (or "literary manager") is a behind-the-scenes individual who
|
13
|
+
researches and advises in the development of dramatic scripts and productions.
|
14
|
+
|
15
|
+
This library hopes to allow you to fulfill a similar role, but for shell scripts and cli workflows.
|
16
|
+
|
17
|
+
In particular, in the spirit of devops and "learn by doing", it seeks to empower those in-the-know (e.g. ops-types or
|
18
|
+
senior developers) to deliver a workflow to those-less-so (e.g. junior developers) that can be executed outright—or
|
19
|
+
easily departed from as desired & appropriate for the user's level of familiarity with the tools & proccess.}
|
20
|
+
spec.homepage = "https://github.com/donaldguy/dramaturg"
|
21
|
+
spec.license = "MIT"
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0")
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency "madCLIbs", '~> 0.0.4'
|
29
|
+
spec.add_dependency "activesupport", '~> 4'
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
34
|
+
#spec.add_development_dependency "rspec"
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'dramaturg'
|
2
|
+
|
3
|
+
$i = Dramaturg::Script.new({
|
4
|
+
#we want to run in order - without this 'new branch' will run first
|
5
|
+
#cause of its output is used in next command; I might make ~promises later
|
6
|
+
run_previous_on_declare: true
|
7
|
+
})
|
8
|
+
def cmd(s,&b); $i.(s,&b) ; end
|
9
|
+
|
10
|
+
#there are several supported syntaxes; this varies between them for
|
11
|
+
#demonstration purposes
|
12
|
+
|
13
|
+
$i.("git status ")
|
14
|
+
|
15
|
+
$i["git commit {-v}"]
|
16
|
+
.name("commit")
|
17
|
+
|
18
|
+
git = cmd("git checkout -b {branch:master}") do
|
19
|
+
name 'new branch'
|
20
|
+
fail_ok true
|
21
|
+
end
|
22
|
+
|
23
|
+
$i.cmd("git push -u origin {#{git[:branch]}}")
|
24
|
+
.run #unfortunately we still need to run the last manually with :run_previous_on_declare
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dramaturg'
|
2
|
+
|
3
|
+
$i = Dramaturg::Script.new({
|
4
|
+
prompter: {
|
5
|
+
class: Dramaturg::Prompter::UseDefaults
|
6
|
+
},
|
7
|
+
runner: {
|
8
|
+
class: Dramaturg::Runner::Print
|
9
|
+
},
|
10
|
+
})
|
11
|
+
at_exit { $i.run_all() }
|
12
|
+
|
13
|
+
git = cmd("git checkout -b {branch:master}")
|
14
|
+
.name('new branch')
|
15
|
+
.fail_ok(true)
|
16
|
+
|
17
|
+
$i["git push -u origin {#{git[:branch]}}"]
|
18
|
+
|
19
|
+
$i["echo 'all up to date'"]
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Dramaturg
|
2
|
+
class Command
|
3
|
+
module HashLike
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
#as part of the interface allowing eager evaluation.
|
7
|
+
#for internal/pre- or mid-run use, use #get
|
8
|
+
def [](k)
|
9
|
+
self.run if !ran?
|
10
|
+
|
11
|
+
if ran? == :aborted
|
12
|
+
"???" #all bets off
|
13
|
+
else
|
14
|
+
get(k)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(k)
|
19
|
+
@values ||= {}
|
20
|
+
if k.is_a? Symbol
|
21
|
+
@values[k]
|
22
|
+
elsif k.respond_to? :to_str
|
23
|
+
k.to_str
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(k,v)
|
28
|
+
@values ||= {}
|
29
|
+
@values[k] = v
|
30
|
+
end
|
31
|
+
|
32
|
+
def <<(v)
|
33
|
+
@line ||= []
|
34
|
+
@line << v
|
35
|
+
end
|
36
|
+
|
37
|
+
def each &b
|
38
|
+
@line.each &b
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
|
4
|
+
module Dramaturg::Command::Opt
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def opt(name, default)
|
9
|
+
self.send(:define_method, name, ->(arg=nil) do
|
10
|
+
iv_symbol = "@opt_#{name.to_s}".to_sym
|
11
|
+
|
12
|
+
if arg.nil? && !self.instance_variable_defined?(iv_symbol)
|
13
|
+
default_value = default.respond_to?(:call)? default.(self) : default
|
14
|
+
self.instance_variable_set(iv_symbol, default_value)
|
15
|
+
end
|
16
|
+
|
17
|
+
if arg != nil
|
18
|
+
arg_value = arg.respond_to?(:call)? arg.(self) : arg
|
19
|
+
self.instance_variable_set(iv_symbol, arg_value)
|
20
|
+
return self #allow chaining
|
21
|
+
end
|
22
|
+
|
23
|
+
self.instance_variable_get(iv_symbol)
|
24
|
+
end)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Dramaturg
|
2
|
+
class Command
|
3
|
+
module Parser
|
4
|
+
def parse!
|
5
|
+
tokens = tokenize(self.to_s)
|
6
|
+
|
7
|
+
tokens.each do |t|
|
8
|
+
case t
|
9
|
+
when /^\{(\w+):(.+)\}$/
|
10
|
+
key = $1.to_sym
|
11
|
+
self[key] = Value::Default.new($2)
|
12
|
+
self << key
|
13
|
+
when /^\{(.+)\}$/
|
14
|
+
key = $1.to_sym
|
15
|
+
self[key] = Value::Default.new($1)
|
16
|
+
self << key
|
17
|
+
else
|
18
|
+
self << Value::Fixed.new(t)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if self.allow_suffix
|
23
|
+
self[:__suffix] = Value::Default.new("")
|
24
|
+
self << :__suffix
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def tokenize(s)
|
30
|
+
s.split /\s+/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'command/hash_like'
|
2
|
+
require_relative 'command/parser'
|
3
|
+
require_relative 'command/opt'
|
4
|
+
|
5
|
+
module Dramaturg
|
6
|
+
class Command
|
7
|
+
include Command::HashLike
|
8
|
+
include Command::Parser
|
9
|
+
include Command::Opt
|
10
|
+
|
11
|
+
opt :name, ->(cmd) { cmd.program_name }
|
12
|
+
opt :program_name, ->(cmd){cmd.to_s[/^\S+/]}
|
13
|
+
opt :aborted, false
|
14
|
+
|
15
|
+
opt :allow_suffix, ->(cmd){!!(cmd.to_s =~ /\s+$/)}
|
16
|
+
opt :capture_output, false
|
17
|
+
opt :fail_ok, false
|
18
|
+
|
19
|
+
attr_accessor :ran
|
20
|
+
alias ran? ran
|
21
|
+
|
22
|
+
def initialize(cmd_str, script)
|
23
|
+
@cmd_str = cmd_str
|
24
|
+
@script = script
|
25
|
+
@ran = false
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
@script.execute(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
def default(v)
|
33
|
+
self.get(v).default
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
@cmd_str
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dramaturg
|
2
|
+
class CtrlCHandler
|
3
|
+
class SkipOrExit
|
4
|
+
def self.call(prompter, cmd)
|
5
|
+
puts "\n^C again to exit; Enter to skip '#{cmd.name}'"
|
6
|
+
|
7
|
+
require 'mad_clibs/util/iohelper'
|
8
|
+
key = IOHelper.read_key(false)
|
9
|
+
|
10
|
+
if key == 'ctrl-c'
|
11
|
+
puts "Okay, bye!"
|
12
|
+
exit!
|
13
|
+
else
|
14
|
+
prompter.abort!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Dramaturg
|
2
|
+
module Prompter
|
3
|
+
class Base
|
4
|
+
attr_reader :current_command
|
5
|
+
|
6
|
+
def initialize(script,config)
|
7
|
+
@script = script
|
8
|
+
@prompt = config[:prompt]
|
9
|
+
@formatters = config[:format]
|
10
|
+
@current_command = nil
|
11
|
+
@abort = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def prompt
|
15
|
+
if @prompt.respond_to? :call
|
16
|
+
@prompt.()
|
17
|
+
else
|
18
|
+
@prompt
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(cmd)
|
23
|
+
@current_command = cmd
|
24
|
+
_call(cmd)
|
25
|
+
end
|
26
|
+
|
27
|
+
def abort!
|
28
|
+
@abort = true
|
29
|
+
self.current_command.aborted(true)
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
require 'madCLIbs'
|
3
|
+
|
4
|
+
module Dramaturg
|
5
|
+
module Prompter
|
6
|
+
class MadCLIbs < Base
|
7
|
+
def initialize(script,config)
|
8
|
+
super
|
9
|
+
@cli = ::MadCLIbs.new
|
10
|
+
@cli.interrupt_handler = ->() { config[:ctrlc].(self, self.current_command) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def _call(cmd)
|
14
|
+
@current_command = cmd
|
15
|
+
@cli.prompt(prompt, *values_to_madclib_tokens(cmd))
|
16
|
+
|
17
|
+
return if @abort
|
18
|
+
|
19
|
+
@values.each do |key, entered|
|
20
|
+
cmd[key] = entered.value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def value_type_to_token_type(t)
|
26
|
+
@type_map ||=
|
27
|
+
{
|
28
|
+
Value::Default => ::MadCLIbs::Blanks::String,
|
29
|
+
Value::Fixed => Value::Fixed #i.e. ::String
|
30
|
+
}
|
31
|
+
@type_map[t]
|
32
|
+
end
|
33
|
+
|
34
|
+
def token_type_to_value_type(t)
|
35
|
+
value_type_to_token_type(t)
|
36
|
+
@reverse_type_map ||= Hash[@type_map.to_a.map(&:reverse)]
|
37
|
+
@reverse_type_map[t]
|
38
|
+
end
|
39
|
+
|
40
|
+
def values_to_madclib_tokens(cmd)
|
41
|
+
@values = {}
|
42
|
+
|
43
|
+
unfmt = cmd.map do |value|
|
44
|
+
if value.is_a? Symbol
|
45
|
+
@values[value] = @cli.string(cmd.default(value))
|
46
|
+
else
|
47
|
+
value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
unfmt.map do |v|
|
52
|
+
@formatters[token_type_to_value_type(v.class)].(v)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Dramaturg
|
4
|
+
module Prompter
|
5
|
+
class UseDefaults < Base
|
6
|
+
def initialize(script,config)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def _call(cmd)
|
11
|
+
print(prompt, " ", values_to_strings(cmd).join(" "), "\n")
|
12
|
+
|
13
|
+
return if @abort
|
14
|
+
|
15
|
+
@values.each do |key,value|
|
16
|
+
cmd[key] = cmd.get(cmd.default(key))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def values_to_strings(cmd)
|
22
|
+
@values = {}
|
23
|
+
|
24
|
+
unfmt = cmd.map do |value|
|
25
|
+
if value.is_a? Symbol
|
26
|
+
@values[value] = cmd.get(value)
|
27
|
+
else
|
28
|
+
value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
unfmt.map do |v|
|
33
|
+
@formatters[v.class].(v)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Dramaturg
|
2
|
+
class Runner::Base
|
3
|
+
def initialize(script,config={})
|
4
|
+
@script = script
|
5
|
+
@last_success = true
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(cmd)
|
9
|
+
if !cmd.aborted
|
10
|
+
line = cmd.map { |v| cmd.get(v) }.join(' ')
|
11
|
+
|
12
|
+
ok = _call(line, cmd)
|
13
|
+
|
14
|
+
cmd.ran = line
|
15
|
+
|
16
|
+
if !ok && !cmd.fail_ok
|
17
|
+
handle_fail(cmd)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
cmd.ran = :aborted
|
21
|
+
ok = false
|
22
|
+
end
|
23
|
+
|
24
|
+
@last_success = ok
|
25
|
+
end
|
26
|
+
|
27
|
+
def last_success?
|
28
|
+
@last_success
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def handle_fail(cmd)
|
33
|
+
raise RuntimeError, "#{cmd.ran} failed"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Dramaturg
|
4
|
+
class Runner::Print < Runner::Base
|
5
|
+
def initialize(script,config={})
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def _call(line,cmd)
|
10
|
+
print "Would run: #{line}"
|
11
|
+
cmd.ran = line
|
12
|
+
|
13
|
+
puts ""
|
14
|
+
return true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Dramaturg
|
4
|
+
class Runner::Shell < Runner::Base
|
5
|
+
def initialize(script, config={})
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def _call(line,cmd)
|
10
|
+
if cmd.capture_output
|
11
|
+
cmd[:output] = `#{line}`
|
12
|
+
ok = !cmd[:output].empty?
|
13
|
+
else
|
14
|
+
ok = system(line)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'term/ansicolor'
|
2
|
+
|
3
|
+
|
4
|
+
module Dramaturg
|
5
|
+
class Script
|
6
|
+
include Term::ANSIColor
|
7
|
+
|
8
|
+
def initialize(config = {})
|
9
|
+
defaults = {
|
10
|
+
prompter: {
|
11
|
+
class: Prompter::MadCLIbs,
|
12
|
+
prompt: ->() {
|
13
|
+
if self.runner.last_success?
|
14
|
+
bold(green("$"))
|
15
|
+
else
|
16
|
+
bold(red("$"))
|
17
|
+
end
|
18
|
+
},
|
19
|
+
format: {
|
20
|
+
Value::Default => ->(s){ bold(cyan(s)) },
|
21
|
+
Value::Fixed => -> (s) { s }
|
22
|
+
},
|
23
|
+
ctrlc: CtrlCHandler::SkipOrExit
|
24
|
+
},
|
25
|
+
runner: {
|
26
|
+
class: Runner::Shell
|
27
|
+
},
|
28
|
+
}
|
29
|
+
|
30
|
+
@config = defaults.deep_merge(config)
|
31
|
+
|
32
|
+
@commands = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def cmd(command_str, &opts)
|
36
|
+
run_all if @config[:run_previous_on_declare]
|
37
|
+
c = Command.new(command_str, self)
|
38
|
+
@commands << c
|
39
|
+
|
40
|
+
if opts
|
41
|
+
c.instance_eval &opts
|
42
|
+
end
|
43
|
+
|
44
|
+
c
|
45
|
+
end
|
46
|
+
alias call cmd
|
47
|
+
alias [] cmd
|
48
|
+
|
49
|
+
def prompter
|
50
|
+
@prompter ||= @config[:prompter][:class].new(
|
51
|
+
self,
|
52
|
+
@config[:prompter]
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def runner
|
57
|
+
@runner ||= @config[:runner][:class].new(
|
58
|
+
self,
|
59
|
+
@config[:runner]
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def execute(cmd)
|
64
|
+
cmd.parse!
|
65
|
+
prompter.(cmd)
|
66
|
+
runner.(cmd)
|
67
|
+
end
|
68
|
+
|
69
|
+
def run_all
|
70
|
+
@commands.each do |cmd|
|
71
|
+
unless cmd.ran?
|
72
|
+
execute(cmd)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/dramaturg.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dramaturg/version'
|
2
|
+
require 'active_support/dependencies/autoload'
|
3
|
+
require 'active_support/core_ext/hash/deep_merge'
|
4
|
+
|
5
|
+
module Dramaturg
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
autoload :Script
|
8
|
+
autoload :Command
|
9
|
+
autoload :Value
|
10
|
+
autoload :Prompter
|
11
|
+
autoload :Runner
|
12
|
+
autoload :CtrlCHandler
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dramaturg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Donald Guy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: madCLIbs
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
description: |-
|
56
|
+
In theater, a dramaturg (or "literary manager") is a behind-the-scenes individual who
|
57
|
+
researches and advises in the development of dramatic scripts and productions.
|
58
|
+
|
59
|
+
This library hopes to allow you to fulfill a similar role, but for shell scripts and cli workflows.
|
60
|
+
|
61
|
+
In particular, in the spirit of devops and "learn by doing", it seeks to empower those in-the-know (e.g. ops-types or
|
62
|
+
senior developers) to deliver a workflow to those-less-so (e.g. junior developers) that can be executed outright—or
|
63
|
+
easily departed from as desired & appropriate for the user's level of familiarity with the tools & proccess.
|
64
|
+
email:
|
65
|
+
- fawkes@mit.edu
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- ".gitignore"
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- dramaturg.gemspec
|
76
|
+
- examples/git_feature_branch.rb
|
77
|
+
- examples/just_print.rb
|
78
|
+
- lib/dramaturg.rb
|
79
|
+
- lib/dramaturg/command.rb
|
80
|
+
- lib/dramaturg/command/hash_like.rb
|
81
|
+
- lib/dramaturg/command/opt.rb
|
82
|
+
- lib/dramaturg/command/parser.rb
|
83
|
+
- lib/dramaturg/ctrl_c_handler.rb
|
84
|
+
- lib/dramaturg/ctrl_c_handler/skip.rb
|
85
|
+
- lib/dramaturg/ctrl_c_handler/skip_or_exit.rb
|
86
|
+
- lib/dramaturg/prompter.rb
|
87
|
+
- lib/dramaturg/prompter/base.rb
|
88
|
+
- lib/dramaturg/prompter/madCLIbs.rb
|
89
|
+
- lib/dramaturg/prompter/use_defaults.rb
|
90
|
+
- lib/dramaturg/runner.rb
|
91
|
+
- lib/dramaturg/runner/base.rb
|
92
|
+
- lib/dramaturg/runner/print.rb
|
93
|
+
- lib/dramaturg/runner/shell.rb
|
94
|
+
- lib/dramaturg/script.rb
|
95
|
+
- lib/dramaturg/value.rb
|
96
|
+
- lib/dramaturg/value/default.rb
|
97
|
+
- lib/dramaturg/value/fixed.rb
|
98
|
+
- lib/dramaturg/version.rb
|
99
|
+
homepage: https://github.com/donaldguy/dramaturg
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: A framework for optionally-interactive shell scripts
|
123
|
+
test_files: []
|