dramaturg 0.0.1 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e353b44eaeebb604d4445bfa5a91f8d4867d2da6
4
- data.tar.gz: 3ca57c447212cd023858c8c68c7f3d40d2599ce6
3
+ metadata.gz: 7228984c00c124aef4319fb44cf8ec07b67a041a
4
+ data.tar.gz: ab2fa0c967516db84cde7aa19958f38ff95c6858
5
5
  SHA512:
6
- metadata.gz: fa8c32f4f351075b5c94cae0e9348849fa570a25f7cacb9b9a1e58f977f2067dd452587f971d132f07c6f4e4d1f98829f7fdab173fc1c3190a1189f9d16c3c62
7
- data.tar.gz: 12895780db2b689eab7c06c5777c894b75cd5d951c47046aaaf4fbd5b29a17bd847c5d1fe09eecbc6b75d7246450014d3368d1603825ce109941828437688361
6
+ metadata.gz: 059a6b0fc54ea306b8a554380bc396d57c60a4f5fd38a95ad28d588c6a70694f0c93790cafa003450535b2a34fd892870af30c5b05bd88c4d6235c35139b0653
7
+ data.tar.gz: e7d290b0b30af27b1b180080caa9aa9d239aed8d56cb7797c58551e96c38669f742707e60e596954494e84edc8058957be908bedfc05b2467574b48ba0515409
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ ## Change Log
2
+
3
+ ### v0.1.0 (2015/02/17 20:01 +00:00)
4
+ - [8879ad3](https://github.com/donaldguy/dramaturg/commit/8879ad33ce818fa60f9eb67b05e53d314ea60566) FIX: restore skip as fail semantics (@donaldguy)
5
+ - [87a1a2a](https://github.com/donaldguy/dramaturg/commit/87a1a2aa5089997e3d3a1e46c2933ccdee120653) REFACTOR: cmd[] only for symbols; consistent to_s (@donaldguy)
6
+ - [b446c66](https://github.com/donaldguy/dramaturg/commit/b446c66c98ba082860e2e921a32c286a69363ece) Workaround for eager-eval output access (@donaldguy)
7
+ - [2fcb94d](https://github.com/donaldguy/dramaturg/commit/2fcb94d1c7c8651e9da9eca54e98f26414c91961) Fixes for Thor (@donaldguy)
8
+ - [36ce457](https://github.com/donaldguy/dramaturg/commit/36ce457155ea878ec27591ebdffef1c4f4382993) Fixed for Skips and Unknown (@donaldguy)
9
+ - [cbe49f4](https://github.com/donaldguy/dramaturg/commit/cbe49f4ed21915d2d5cf038d252f87200c7397e6) Substantial Refactor of ~All internals (@donaldguy)
10
+ - [2f086e3](https://github.com/donaldguy/dramaturg/commit/2f086e34ee13f668062dec5a68c72072dfbc3dcc) Allow for masked values ("virtual environment variables") (@donaldguy)
11
+ - [2bb80d8](https://github.com/donaldguy/dramaturg/commit/2bb80d85246b37aa15d159932205590e0df3c9da) Allow stealth `tee` to a file as cmd#save_to_file (@donaldguy)
12
+ - [b4b1713](https://github.com/donaldguy/dramaturg/commit/b4b1713c5b36f33c8aac73066dd3ab517a5f8f34) Add thor-compatible runner and import-path (@donaldguy)
13
+ - [0f7e019](https://github.com/donaldguy/dramaturg/commit/0f7e019934165bf532108703daf56a1e5065c2e2) Allow non-space-delimited overridable fields (@donaldguy)
14
+ - [a584174](https://github.com/donaldguy/dramaturg/commit/a584174b8ce9d2ebd25eda07fac219bd815b58ef) Move default config to class-level constant (@donaldguy)
15
+ - [ae24769](https://github.com/donaldguy/dramaturg/commit/ae247696e8366b3bf775a93e57c151d0312630cc) Return self after run for code like (@donaldguy)
16
+ - [a2ee66e](https://github.com/donaldguy/dramaturg/commit/a2ee66e6a74cf8f4f72fe132050c74e40a066a4e) README badges (@donaldguy)
17
+
18
+ ### v0.0.1 (2015/02/16 05:23 +00:00)
19
+ - [da395cb](https://github.com/donaldguy/dramaturg/commit/da395cb5ce793f25ec871b42b8f95a5c7c1f312c) deliver on "optionally" with UseDefault Prompter (@donaldguy)
20
+ - [2b0e752](https://github.com/donaldguy/dramaturg/commit/2b0e752a2b29c60f946a264a0a6e5ac9ddd67a6a) Add some pluggable int handlers; fancy prompt (@donaldguy)
21
+ - [b6903cd](https://github.com/donaldguy/dramaturg/commit/b6903cd3a4fb1e7b5fbdb53ae2818d944f1b765c) Provisional Custom Interrupt Handling (@donaldguy)
22
+ - [33dcec2](https://github.com/donaldguy/dramaturg/commit/33dcec2c0fc3768088eadd2227fac1183f6eec7e) Refactor config interface (@donaldguy)
23
+ - [b3491e0](https://github.com/donaldguy/dramaturg/commit/b3491e01ee89fd0d7e85d0c9e9b4669ad444a5b7) Working proof of concept (@donaldguy)
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Dramaturg: Optionally-interactive shell scripts
1
+ # Dramaturg: <br>Optionally-interactive shell scripts
2
+ [![Gem Version](https://badge.fury.io/rb/dramaturg.svg)](http://badge.fury.io/rb/dramaturg) [![Code Climate](https://codeclimate.com/github/donaldguy/dramaturg/badges/gpa.svg)](https://codeclimate.com/github/donaldguy/dramaturg) [![Dependency Status](https://gemnasium.com/donaldguy/dramaturg.svg)](https://gemnasium.com/donaldguy/dramaturg)
3
+
2
4
 
3
5
  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
6
 
data/dramaturg.gemspec CHANGED
@@ -25,7 +25,7 @@ easily departed from as desired & appropriate for the user's level of familiarit
25
25
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency "madCLIbs", '~> 0.0.4'
28
+ spec.add_dependency "madCLIbs", '~> 0.0.5'
29
29
  spec.add_dependency "activesupport", '~> 4'
30
30
 
31
31
 
@@ -8,12 +8,13 @@ $i = Dramaturg::Script.new({
8
8
  class: Dramaturg::Runner::Print
9
9
  },
10
10
  })
11
- at_exit { $i.run_all() }
12
11
 
13
- git = cmd("git checkout -b {branch:master}")
12
+ git = $i.cmd("git checkout -b {branch:master}")
14
13
  .name('new branch')
15
14
  .fail_ok(true)
16
15
 
17
16
  $i["git push -u origin {#{git[:branch]}}"]
18
17
 
19
18
  $i["echo 'all up to date'"]
19
+
20
+ $i.run_all
@@ -0,0 +1,11 @@
1
+ require 'dramaturg'
2
+
3
+ $i = Dramaturg::Script.new()
4
+ at_exit { $i.run_all() }
5
+
6
+ puts "secretly saving to ls.out"
7
+ $i['ls -{l}']
8
+ .save_to_file('ls.out')
9
+
10
+ $i["cat ls.out"]
11
+ $i["rm ls.out"]
@@ -0,0 +1,8 @@
1
+ require 'dramaturg'
2
+
3
+ $i = Dramaturg::Script.new()
4
+ at_exit { $i.run_all() }
5
+
6
+ $GREETING = $i.masked_value("hello")
7
+
8
+ $i["echo {$GREETING} {world}"]
@@ -0,0 +1,32 @@
1
+ module Dramaturg
2
+ class Command
3
+ module AsCollection
4
+ include Enumerable
5
+
6
+ def each &b
7
+ @values.each &b
8
+ end
9
+
10
+ def [](i)
11
+ run unless ran?
12
+ if self.respond_to? i
13
+ self.send i
14
+ else
15
+ @outputs[i].for_prompt
16
+ end
17
+ end
18
+
19
+ def []=(i,v)
20
+ @outputs[i] = v
21
+ end
22
+
23
+ def <<(v)
24
+ @values << v
25
+ end
26
+
27
+ def output
28
+ @outputs[:output]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,40 +1,59 @@
1
- require_relative 'command/hash_like'
2
- require_relative 'command/parser'
1
+ require_relative 'command/as_collection'
3
2
  require_relative 'command/opt'
4
3
 
5
4
  module Dramaturg
6
5
  class Command
7
- include Command::HashLike
8
- include Command::Parser
6
+ include Command::AsCollection
9
7
  include Command::Opt
10
8
 
11
- opt :name, ->(cmd) { cmd.program_name }
12
- opt :program_name, ->(cmd){cmd.to_s[/^\S+/]}
13
- opt :aborted, false
9
+ opt :name, ->(cmd) { cmd.to_s[/^[^\{]+/].strip }
10
+ opt :program_name, ->(cmd) { cmd.to_s[/^\S+/] }
14
11
 
12
+ #prompt behavior
15
13
  opt :allow_suffix, ->(cmd){!!(cmd.to_s =~ /\s+$/)}
16
- opt :capture_output, false
14
+
15
+ #run behavior
17
16
  opt :fail_ok, false
18
17
 
19
- attr_accessor :ran
20
- alias ran? ran
18
+ #output direction
19
+ opt :capture_output, false
20
+ opt :save_to_file, false
21
21
 
22
22
  def initialize(cmd_str, script)
23
- @cmd_str = cmd_str
23
+ @input_string = cmd_str
24
24
  @script = script
25
- @ran = false
25
+ @values = []
26
+ @outputs = {}
26
27
  end
27
28
 
28
29
  def run
29
30
  @script.execute(self)
31
+ self
32
+ end
33
+ attr_accessor :ran
34
+ def ran?
35
+ @ran ||= false
36
+ @ran || @skipped
30
37
  end
31
38
 
32
- def default(v)
33
- self.get(v).default
39
+ def skip
40
+ @ok = :skipped
41
+ @skipped = true
42
+ @outputs.each {|k,_| @outputs[k] = Value::Unknown.new() }
34
43
  end
44
+ def skipped?; @skipped ||= false; end
45
+
46
+ attr_accessor :ok
47
+ alias ok? ok
48
+ alias success? ok
49
+ alias succeeded? ok
35
50
 
36
51
  def to_s
37
- @cmd_str
52
+ if @values.empty?
53
+ @input_string
54
+ else
55
+ self.map {|t| t.to_s}.join ''
56
+ end
38
57
  end
39
58
  end
40
59
  end
@@ -2,7 +2,7 @@ module Dramaturg
2
2
  class CtrlCHandler
3
3
  class SkipOrExit
4
4
  def self.call(prompter, cmd)
5
- puts "\n^C again to exit; Enter to skip '#{cmd.name}'"
5
+ puts "\n^C again to exit; Any other key to skip '#{cmd.name}'"
6
6
 
7
7
  require 'mad_clibs/util/iohelper'
8
8
  key = IOHelper.read_key(false)
@@ -0,0 +1,62 @@
1
+ module Dramaturg
2
+ class Parser
3
+ class <<self
4
+ def call(cmd)
5
+ tokens = tokenize(cmd.to_s)
6
+
7
+ tokens.each do |t|
8
+ case t
9
+ when /^\{(\w+):(.+)\}$/
10
+ add_named_value(cmd, $1.to_sym, $2)
11
+ when /^\{([^\$].*)\}$/
12
+ add_anon_value(cmd, $1)
13
+ when /^\{(\$.+)\}/
14
+ add_var_value(cmd, $1)
15
+ else
16
+ cmd << Value::Fixed.new(t)
17
+ end
18
+ end
19
+
20
+ if cmd.allow_suffix
21
+ suffix = Value::OrDefault.new("")
22
+ cmd[:_suffix] = suffix
23
+ cmd << suffix
24
+ end
25
+
26
+ if cmd.save_to_file
27
+ cmd << Value::Silent.new(" | tee #{cmd.save_to_file}")
28
+ end
29
+ end
30
+
31
+ private
32
+ def tokenize(s)
33
+ s.split /(?=\{)|(?<=\})/
34
+ end
35
+
36
+ def add_anon_value(cmd, expression)
37
+ cmd << Value::OrDefault.new(expression)
38
+ end
39
+
40
+ def add_named_value(cmd, name, value)
41
+ value = Value::OrDefault.new(value)
42
+ cmd[name] = value
43
+ cmd << value
44
+ end
45
+
46
+ def add_var_value(cmd, var)
47
+ exists = eval("defined? #{var}")
48
+ key = var.to_sym
49
+
50
+ if exists == 'global-variable'
51
+ value = eval(var)
52
+ value = Value::Fixed(value) unless value.is_a? Value::Base
53
+ value.display = var if value.respond_to? :display=
54
+
55
+ cmd << value
56
+ else
57
+ $stderr.puts "WARN: Reference to undefined global #{$1} at #{caller(7).join("\n\t")}"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,34 +1,46 @@
1
1
  module Dramaturg
2
2
  module Prompter
3
3
  class Base
4
- attr_reader :current_command
4
+ attr_reader :script
5
5
 
6
6
  def initialize(script,config)
7
7
  @script = script
8
8
  @prompt = config[:prompt]
9
9
  @formatters = config[:format]
10
- @current_command = nil
11
- @abort = false
12
- end
13
10
 
14
- def prompt
15
- if @prompt.respond_to? :call
16
- @prompt.()
17
- else
18
- @prompt
19
- end
11
+ @current_command = nil
20
12
  end
21
13
 
22
14
  def call(cmd)
23
15
  @current_command = cmd
24
- _call(cmd)
16
+ value_map = prepare_values(cmd)
17
+ display = format_for_display(value_map)
18
+
19
+ results = doIO(display, value_map)
20
+
21
+ process_results(results, value_map)
25
22
  end
26
23
 
27
24
  def abort!
28
- @abort = true
29
- self.current_command.aborted(true)
25
+ @current_command.skip
30
26
  return false
31
27
  end
28
+
29
+ private
30
+ def prompt_for_display
31
+ if @prompt.respond_to? :call
32
+ @prompt.(self)
33
+ else
34
+ @prompt
35
+ end
36
+ end
37
+
38
+ def prepare_values(cmd, debug=false)
39
+ cmd.map do |v|
40
+ str = debug ? v.for_debug_prompt : v.for_prompt
41
+ [v, tr_method_map[v].(str)]
42
+ end.to_h
43
+ end
32
44
  end
33
45
  end
34
46
  end
@@ -4,52 +4,40 @@ require 'madCLIbs'
4
4
  module Dramaturg
5
5
  module Prompter
6
6
  class MadCLIbs < Base
7
+ attr_reader :current_command
8
+
7
9
  def initialize(script,config)
8
10
  super
9
- @cli = ::MadCLIbs.new
11
+ @cli = ::MadCLIbs.new(separator: '')
10
12
  @cli.interrupt_handler = ->() { config[:ctrlc].(self, self.current_command) }
11
13
  end
12
14
 
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
15
+ private
16
+ def tr_method_map
17
+ proc do |v|
18
+ if v.kind_of? Value::OrDefault
19
+ @cli.method :string
20
+ else
21
+ String.method :new
22
+ end
21
23
  end
22
24
  end
23
25
 
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]
26
+ def format_for_display(map)
27
+ ([prompt_for_display] +
28
+ map.map do |k,v|
29
+ @formatters[k.class].(v)
30
+ end
31
+ )
32
32
  end
33
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]
34
+ def doIO(display, map)
35
+ @cli.prompt(*display)
38
36
  end
39
37
 
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)
38
+ def process_results(results, map)
39
+ map.each do |dmt_v, mcli_t|
40
+ dmt_v.input(mcli_t.to_s) if dmt_v.respond_to? :input
53
41
  end
54
42
  end
55
43
  end
@@ -7,31 +7,24 @@ module Dramaturg
7
7
  super
8
8
  end
9
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
10
+ private
11
+ def tr_method_map
12
+ proc {|s| Kernel.method :String }
18
13
  end
19
14
 
20
- private
21
- def values_to_strings(cmd)
22
- @values = {}
15
+ def format_for_display(map)
16
+ prompt_for_display +
17
+ map.map do |k,v|
18
+ @formatters[k.class].(v)
19
+ end.join('')
20
+ end
23
21
 
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
22
+ def doIO(display,map)
23
+ puts display
24
+ end
31
25
 
32
- unfmt.map do |v|
33
- @formatters[v.class].(v)
34
- end
26
+ def process_results(*args)
27
+ #no input
35
28
  end
36
29
  end
37
30
  end
@@ -6,22 +6,18 @@ module Dramaturg
6
6
  end
7
7
 
8
8
  def call(cmd)
9
- if !cmd.aborted
10
- line = cmd.map { |v| cmd.get(v) }.join(' ')
11
-
12
- ok = _call(line, cmd)
9
+ unless cmd.skipped?
10
+ line = cmd.map { |v| v.for_run }.join('')
13
11
 
14
12
  cmd.ran = line
13
+ _call(line, cmd)
15
14
 
16
- if !ok && !cmd.fail_ok
15
+ if !cmd.ok? && !cmd.fail_ok
17
16
  handle_fail(cmd)
18
17
  end
19
- else
20
- cmd.ran = :aborted
21
- ok = false
22
18
  end
23
19
 
24
- @last_success = ok
20
+ @last_success = (cmd.success? && !cmd.skipped?)
25
21
  end
26
22
 
27
23
  def last_success?
@@ -7,11 +7,9 @@ module Dramaturg
7
7
  end
8
8
 
9
9
  def _call(line,cmd)
10
- print "Would run: #{line}"
11
- cmd.ran = line
10
+ puts "Would run: #{line}"
12
11
 
13
- puts ""
14
- return true
12
+ cmd.ok = true
15
13
  end
16
14
  end
17
15
  end
@@ -8,10 +8,11 @@ module Dramaturg
8
8
 
9
9
  def _call(line,cmd)
10
10
  if cmd.capture_output
11
- cmd[:output] = `#{line}`
12
- ok = !cmd[:output].empty?
11
+ output = `#{line}`
12
+ cmd[:output] = output
13
+ cmd.ok = !output.empty?
13
14
  else
14
- ok = system(line)
15
+ cmd.ok = system(line)
15
16
  end
16
17
  end
17
18
  end
@@ -0,0 +1,20 @@
1
+ require_relative 'base'
2
+
3
+ module Dramaturg
4
+ class Runner::Thor < Runner::Base
5
+ def initialize(script, config={})
6
+ super
7
+ @thor_actions = config[:thor_actions]
8
+ end
9
+
10
+ def _call(line,cmd)
11
+ if cmd.capture_output
12
+ output = @thor_actions.run(line, verbose: false, capture: true)
13
+ cmd[:output] = output
14
+ cmd.ok = !output.empty?
15
+ else
16
+ cmd.ok = @thor_actions.run(line, verbose:false)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -4,5 +4,6 @@ module Dramaturg
4
4
 
5
5
  autoload :Print
6
6
  autoload :Shell
7
+ autoload :Thor
7
8
  end
8
9
  end
@@ -1,33 +1,7 @@
1
- require 'term/ansicolor'
2
-
3
-
4
1
  module Dramaturg
5
2
  class Script
6
- include Term::ANSIColor
7
-
8
3
  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)
4
+ @config = Dramaturg::DEFAULT_CONFIG.deep_merge(config)
31
5
 
32
6
  @commands = []
33
7
  end
@@ -46,22 +20,12 @@ module Dramaturg
46
20
  alias call cmd
47
21
  alias [] cmd
48
22
 
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
- )
23
+ def masked_value(str)
24
+ Value::Masked.new(str)
61
25
  end
62
26
 
63
27
  def execute(cmd)
64
- cmd.parse!
28
+ parser.(cmd)
65
29
  prompter.(cmd)
66
30
  runner.(cmd)
67
31
  end
@@ -73,5 +37,23 @@ module Dramaturg
73
37
  end
74
38
  end
75
39
  end
40
+
41
+ def parser
42
+ @config[:parser][:class]
43
+ end
44
+
45
+ def prompter
46
+ @prompter ||= @config[:prompter][:class].new(
47
+ self,
48
+ @config[:prompter]
49
+ )
50
+ end
51
+
52
+ def runner
53
+ @runner ||= @config[:runner][:class].new(
54
+ self,
55
+ @config[:runner]
56
+ )
57
+ end
76
58
  end
77
59
  end
@@ -0,0 +1,14 @@
1
+ require 'dramaturg'
2
+
3
+ module Dramaturg
4
+ def self.Thor(thor_actions_object, config = {})
5
+ config = ({
6
+ runner: {
7
+ class: Dramaturg::Runner::Thor,
8
+ thor_actions: thor_actions_object
9
+ }
10
+ }).deep_merge(config)
11
+
12
+ Dramaturg::Script.new(config)
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ module Dramaturg
2
+ module Value
3
+ class Base
4
+ def initialize(value)
5
+ @value = value
6
+ end
7
+
8
+ def for_prompt
9
+ @value
10
+ end
11
+
12
+ def for_debug_prompt
13
+ @value
14
+ end
15
+
16
+ def for_run
17
+ @value
18
+ end
19
+
20
+ #for tokens which accept input add a
21
+ #def input(i)
22
+ # # modify state
23
+ #end
24
+
25
+ # should match parser input
26
+ def to_s
27
+ for_prompt
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,4 +1,8 @@
1
+ require_relative 'base'
2
+
1
3
  module Dramaturg
2
- class Value::Fixed < String
4
+ module Value
5
+ class Fixed < Base
6
+ end
3
7
  end
4
8
  end
@@ -0,0 +1,24 @@
1
+ require_relative 'base'
2
+
3
+ module Dramaturg
4
+ class Value::Masked < Value::Base
5
+ attr_writer :display
6
+
7
+ def initialize(value)
8
+ @display = '$SECRET'
9
+ super(value)
10
+ end
11
+
12
+ def for_prompt
13
+ @display
14
+ end
15
+
16
+ def to_s
17
+ "{#@display}"
18
+ end
19
+
20
+ def inspect
21
+ "{#@display = #@value}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'base'
2
+
3
+ module Dramaturg
4
+ module Value
5
+ class OrDefault < Base
6
+ def initialize(value)
7
+ @default = value
8
+ super(value)
9
+ end
10
+
11
+ def input(i)
12
+ @value = i
13
+ end
14
+
15
+ def to_s
16
+ "{#@value}"
17
+ end
18
+
19
+ def inspect
20
+ "{#@value (default: #@dfault)}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'base'
2
+
3
+ module Dramaturg
4
+ class Value::Silent < Value::Base
5
+ def initialize(value)
6
+ super(value)
7
+ end
8
+
9
+ def for_prompt
10
+ ""
11
+ end
12
+
13
+ def inspect
14
+ "{{silent: '#{@value}'}}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'or_default'
2
+
3
+ module Dramaturg
4
+ module Value
5
+ class Unknown < OrDefault
6
+ def initialize()
7
+ super(nil)
8
+ end
9
+
10
+ def for_prompt
11
+ '???'
12
+ end
13
+
14
+ def for_run
15
+ if @value == nil
16
+ raise ArgumentError, "You must set a value"
17
+ else
18
+ @value
19
+ end
20
+ end
21
+
22
+ def to_s
23
+ "{{unknown}}"
24
+ end
25
+ alias inspect to_s
26
+ end
27
+ end
28
+ end
@@ -3,6 +3,9 @@ module Dramaturg
3
3
  extend ActiveSupport::Autoload
4
4
 
5
5
  autoload :Fixed
6
- autoload :Default
6
+ autoload :OrDefault
7
+ autoload :Silent
8
+ autoload :Masked
9
+ autoload :Unknown
7
10
  end
8
11
  end
@@ -1,3 +1,3 @@
1
1
  module Dramaturg
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/dramaturg.rb CHANGED
@@ -1,13 +1,44 @@
1
- require 'dramaturg/version'
2
1
  require 'active_support/dependencies/autoload'
3
2
  require 'active_support/core_ext/hash/deep_merge'
3
+ require 'term/ansicolor'
4
4
 
5
5
  module Dramaturg
6
6
  extend ActiveSupport::Autoload
7
- autoload :Script
8
- autoload :Command
9
- autoload :Value
10
- autoload :Prompter
11
- autoload :Runner
12
- autoload :CtrlCHandler
7
+ autoload :Parser
8
+ autoload :Script
9
+ autoload :Command
10
+ autoload :Value
11
+ autoload :Prompter
12
+ autoload :Runner
13
+ autoload :CtrlCHandler
14
+
15
+ COLORS = Term::ANSIColor
16
+
17
+
18
+ DEFAULT_CONFIG = {
19
+ parser: {
20
+ class: Parser
21
+ },
22
+ prompter: {
23
+ class: Prompter::MadCLIbs,
24
+ prompt: ->(p) {
25
+ if p.script.runner.last_success?
26
+ COLORS.bold(COLORS.green("$ "))
27
+ else
28
+ COLORS.bold(COLORS.red("$ "))
29
+ end
30
+ },
31
+ format: (proc do |t|
32
+ if t <= Value::OrDefault
33
+ ->(s) { COLORS.bold(COLORS.cyan(s)) }
34
+ else
35
+ ->(s) { s }
36
+ end
37
+ end),
38
+ ctrlc: CtrlCHandler::SkipOrExit
39
+ },
40
+ runner: {
41
+ class: Runner::Shell
42
+ }
43
+ }
13
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dramaturg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Guy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: madCLIbs
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.4
19
+ version: 0.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.4
26
+ version: 0.0.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,6 +68,7 @@ extensions: []
68
68
  extra_rdoc_files: []
69
69
  files:
70
70
  - ".gitignore"
71
+ - CHANGELOG.md
71
72
  - Gemfile
72
73
  - LICENSE.txt
73
74
  - README.md
@@ -75,14 +76,16 @@ files:
75
76
  - dramaturg.gemspec
76
77
  - examples/git_feature_branch.rb
77
78
  - examples/just_print.rb
79
+ - examples/tee_test.rb
80
+ - examples/virtual_env_vars.rb
78
81
  - lib/dramaturg.rb
79
82
  - lib/dramaturg/command.rb
80
- - lib/dramaturg/command/hash_like.rb
83
+ - lib/dramaturg/command/as_collection.rb
81
84
  - lib/dramaturg/command/opt.rb
82
- - lib/dramaturg/command/parser.rb
83
85
  - lib/dramaturg/ctrl_c_handler.rb
84
86
  - lib/dramaturg/ctrl_c_handler/skip.rb
85
87
  - lib/dramaturg/ctrl_c_handler/skip_or_exit.rb
88
+ - lib/dramaturg/parser.rb
86
89
  - lib/dramaturg/prompter.rb
87
90
  - lib/dramaturg/prompter/base.rb
88
91
  - lib/dramaturg/prompter/madCLIbs.rb
@@ -91,10 +94,16 @@ files:
91
94
  - lib/dramaturg/runner/base.rb
92
95
  - lib/dramaturg/runner/print.rb
93
96
  - lib/dramaturg/runner/shell.rb
97
+ - lib/dramaturg/runner/thor.rb
94
98
  - lib/dramaturg/script.rb
99
+ - lib/dramaturg/thor.rb
95
100
  - lib/dramaturg/value.rb
96
- - lib/dramaturg/value/default.rb
101
+ - lib/dramaturg/value/base.rb
97
102
  - lib/dramaturg/value/fixed.rb
103
+ - lib/dramaturg/value/masked.rb
104
+ - lib/dramaturg/value/or_default.rb
105
+ - lib/dramaturg/value/silent.rb
106
+ - lib/dramaturg/value/unknown.rb
98
107
  - lib/dramaturg/version.rb
99
108
  homepage: https://github.com/donaldguy/dramaturg
100
109
  licenses:
@@ -121,3 +130,4 @@ signing_key:
121
130
  specification_version: 4
122
131
  summary: A framework for optionally-interactive shell scripts
123
132
  test_files: []
133
+ has_rdoc:
@@ -1,42 +0,0 @@
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
@@ -1,34 +0,0 @@
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
@@ -1,11 +0,0 @@
1
- module Dramaturg
2
- class Value::Default
3
- def initialize(val)
4
- @val = val
5
- end
6
-
7
- def default
8
- @val
9
- end
10
- end
11
- end