stack_loop 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stack_loop/app.rb +45 -18
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc67ea44a103f6c3d7321520c5e513711bdf3483
4
- data.tar.gz: 9eed716be05d7546f0d9b924f7a66a561bb131e1
3
+ metadata.gz: cc81712c3e789d109bfae88923d192a92e9861af
4
+ data.tar.gz: f7450251ba830fa605ee00a33896c35e158bd46a
5
5
  SHA512:
6
- metadata.gz: 2219b1e2e8138275698578f17b4335af98f76c954aeb361cf15766555334b05aa266d21edd6f0c743ae01b2c892fb1b9ebeff9d7e17f8038d530d2eba5e1350b
7
- data.tar.gz: 738046750d39cb3ab65c879283029d121d4f6f81c8d6fdeab1a58298c22b2e3bf0e15ae69382d59682180a061e3cf833a67e6e5ab2c544211dca3e1c5c8083f0
6
+ metadata.gz: 24c9c520ad3d6b5fb2da442858df29054eb83a8e205f3aee555b2b100ba609c918b957824349572b2c05476db34f09a86c36a34d57ff9ef8441ad8995bbdcbd6
7
+ data.tar.gz: 310f47536bafddb9d03ea2fc7b8a59875cc5dd49b380695439b015f7708965470acef7b0a59e7b7cca6df49e6a7c67b0142ff403cf3f9918bf75711c7178bc5b
@@ -11,17 +11,21 @@ module StackLoop
11
11
  @action = action
12
12
  end
13
13
 
14
- def run
15
- @action.call
14
+ def run(arg_array)
15
+ @action.call(arg_array)
16
16
  end
17
17
  end
18
18
 
19
19
  def commands
20
20
  [
21
21
  Command.new("run"){ run_stack_loop },
22
+ Command.new("try"){ run_top },
22
23
  Command.new("collect"){ push_new; run_stack_loop },
24
+ Command.new("list"){ read_stack; @stack.reverse_each{|argset| puts "- #{command_line(argset).join(" ")}"} },
23
25
  Command.new("pop"){ pop_argset },
24
- Command.new("quit"){ raise "Quitting!" },
26
+ Command.new("push"){|args| push_argset(args)},
27
+ Command.new("edit"){ edit_stack },
28
+ Command.new("quit"){ throw :quit },
25
29
  Command.new("help"){ puts "Don't know that one - try: #{command_names.join(", ")}" }
26
30
  ]
27
31
  end
@@ -86,6 +90,17 @@ module StackLoop
86
90
  @stack.length
87
91
  end
88
92
 
93
+ def edit_stack
94
+ write_stack
95
+ execute_editor_command(stack_file)
96
+ read_stack
97
+ end
98
+
99
+ def execute_editor_command(path)
100
+ editor = ENV["EDITOR"] || "vim"
101
+ system(editor, path)
102
+ end
103
+
89
104
  def run
90
105
  validate_options!
91
106
 
@@ -95,16 +110,19 @@ module StackLoop
95
110
 
96
111
  abbreviations = Abbrev.abbrev(command_names)
97
112
 
98
- loop do
99
- prompt
100
- command_name = $stdin.gets.chomp
101
- if command_name.empty?
102
- command_name = "run"
113
+ catch :quit do
114
+ loop do
115
+ prompt
116
+ command_line = $stdin.gets.chomp.split(/\s+/)
117
+ command_name = command_line.shift
118
+ if command_name.nil?
119
+ command_name = "run"
120
+ end
121
+
122
+ command_name = abbreviations[command_name]
123
+ command = command_hash.fetch(command_name, command_hash["help"])
124
+ command.run(command_line)
103
125
  end
104
-
105
- command_name = abbreviations[command_name]
106
- command = command_hash.fetch(command_name, command_hash["help"])
107
- command.run
108
126
  end
109
127
  end
110
128
 
@@ -113,9 +131,11 @@ module StackLoop
113
131
  end
114
132
 
115
133
  def current_command_line
116
- args = get_argset
134
+ command_line(get_argset)
135
+ end
117
136
 
118
- command_list + get_argset
137
+ def command_line(argset)
138
+ command_list + argset
119
139
  end
120
140
 
121
141
  def prompt
@@ -135,22 +155,29 @@ module StackLoop
135
155
  def run_stack_loop
136
156
  while run_stack
137
157
  puts
138
- puts "Success - running again..."
158
+ puts "Success running next..."
139
159
  puts
140
160
  end
161
+
162
+ run_top if @stack.empty?
141
163
  end
142
164
 
143
165
  def run_stack
144
- success = system(*current_command_line)
166
+ return false if @stack.empty?
167
+
168
+ success = run_top
145
169
 
146
170
  if success.nil?
147
171
  raise "#{[command, *args].inspect} couldn't be run"
148
172
  end
149
173
  pop_argset if success
150
174
 
151
- return false if @stack.empty?
152
-
153
175
  return success
154
176
  end
177
+
178
+ def run_top
179
+ puts current_command_line.join(" ")
180
+ system(*current_command_line)
181
+ end
155
182
  end
156
183
  end
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_loop
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
  - Judson Lester
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-16 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  The idea here is to take arguments off of a stack, run a command, and proceed down the stack iff the command
15
15
  exits 0.
16
16
 
17
- Why? Consider running rspec with a tight focus, adding bredth on success
17
+ Why? Consider running rspec with a tight focus, adding breadth on success
18
18
  email:
19
19
  - nyarly@gmail.com
20
20
  executables:
@@ -36,7 +36,7 @@ rdoc_options:
36
36
  - --main
37
37
  - doc/README
38
38
  - --title
39
- - stack_loop-0.0.1 Documentation
39
+ - stack_loop-0.1.0 Documentation
40
40
  require_paths:
41
41
  - lib/
42
42
  required_ruby_version: !ruby/object:Gem::Requirement