mysh 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f48cf4dd1465e70ce3a405c1bfe36b4ec8d2f9e7
4
- data.tar.gz: 4d2b8050dcb6d6b2bc7dc98c8cd46e3f5e3c94f0
3
+ metadata.gz: e474248b127024d5dc807794564924ba04f5f21c
4
+ data.tar.gz: 712489e71e81a7202a2a54c7d1b18fc67fc58628
5
5
  SHA512:
6
- metadata.gz: 8aa9d57df88528886ef6784d8ff4c0ca974ebe807f8197e4c4f89133ce4ceae116e3cada4939b0a01d17855e8b9f378eabb8c33308302f4447a66cd8306ea43d
7
- data.tar.gz: 4d8a2012d6abe99be8bfdb8929c25d780a6318e1474d7bafecd7cfd57fcad1cc9f50f2dec92bbd44d87b1d832d6a9ba272e60dcd970768dd35531979002b6b76
6
+ metadata.gz: 2d9b6f82a8a2bc3430f209753b7a07753aa74dfcda8a6233bc010ef7eb15a45490b214ffe63ff1edae3e1c18ebc24a1c6a11909711664f14be6c913139c9e8c0
7
+ data.tar.gz: 24073b1333985dae86d44167841b7ca41d91401606cf1a4ca702a1b205702f9da474d9b98e531ac213a8ddda79dddc0b3283417a46a1b9ff3f913d0b52f39bd3
data/README.md CHANGED
@@ -45,11 +45,16 @@ Or install it yourself as:
45
45
 
46
46
  ## Usage
47
47
 
48
- The mysh gem includes a simple executable called mysh. When run, the user is
49
- presented with a command prompt:
48
+ The mysh gem includes a simple executable called mysh. Command entry is a
49
+ typical cli. For more information, see the mini_readline gem at
50
+ ( https://github.com/PeterCamilleri/mini_readline )
50
51
 
51
- $ mysh
52
- mysh>
52
+ When running mysh, the user is presented with a command prompt:
53
+
54
+ ```
55
+ $ mysh
56
+ mysh>
57
+ ```
53
58
 
54
59
  Then start entering some commands! This prompt can be used to execute four
55
60
  sorts of commands:
@@ -76,6 +81,26 @@ reset Reset the execution environment to the default state.
76
81
  result Returns the result of the previous expression.
77
82
  x.lineage Get the class lineage of the object x.
78
83
  ```
84
+ For example:
85
+ ```
86
+ mysh>=a=42
87
+ 42
88
+ mysh>=a
89
+ 42
90
+ mysh>=result
91
+ 42
92
+ mysh>=a.lineage
93
+ "Fixnum instance < Fixnum < Integer < Numeric < Object < BasicObject"
94
+ mysh>=reset
95
+
96
+ mysh>=a
97
+ NameError: undefined local variable or method `a' for #<Mysh::ExecHost:0x1d71e18 @owner=Mysh>
98
+ mysh>=result
99
+
100
+ mysh>
101
+ ```
102
+
103
+
79
104
 
80
105
  The Ruby expression execution environment has direct access to many advanced
81
106
  Math functions. For example, to compute the cosine of 3.141592653589793 use:
@@ -125,31 +150,54 @@ Internal commands are recognized by name and are executed by mysh directly.
125
150
  The following set of commands are supported:
126
151
 
127
152
  ```
128
- ! Display the mysh command history.
129
- ? <topic> Display help information for mysh with an optional topic.
130
- cd <dir> Change directory to the optional <dir> parameter and then display
131
- the current working directory.
132
- exit Exit mysh.
133
- help <topic> Display help information for mysh with an optional topic.
134
- history Display the mysh command history.
135
- pwd Display the current working directory.
136
- quit Exit mysh.
137
- show <file> Display a text file with optional embedded handlebars.
138
- vls <mask> Display the loaded modules, matching the optional mask, that have
139
- version info.
153
+ !<index> Display the mysh command history, or if an index is specified,
154
+ retrieve the command with that index value.
155
+ ?<topic> Display help information for mysh with an optional topic.
156
+ @<item> Display information about a part of mysh. See ?@ for more.
157
+ cd <dir> Change directory to the optional <dir> parameter and then
158
+ display the current working directory.
159
+ exit Exit mysh.
160
+ gls <-l> <mask> Display the loaded ruby gems. See ?gls for more.
161
+ help <topic> Display help information for mysh with an optional topic.
162
+ history <index> Display the mysh command history, or if an index is specified,
163
+ retrieve the command with that index value.
164
+ pwd Display the current working directory.
165
+ quit Exit mysh.
166
+ show <item> Display information about a part of mysh. See ?@ for more.
167
+ type Display a text file with optional embedded handlebars.
168
+ vls <mask> Display the loaded modules, matching the optional mask, that
169
+ have version info.
140
170
  ```
141
- Of note is the command "help help" which provides a list of available topics.
171
+ Of note is the command "help help" or "??" which provides a list of all
172
+ available help topics.
142
173
 
143
- The help (or ?) command is used to get either general help about mysh
144
- or an optional specified topic.
145
-
146
- The available help topics are:
147
-
148
- General help on mysh.
149
- = Help on mysh ruby expressions.
150
- ? Help on mysh help.
151
- help Help on mysh help.
152
- math Help on mysh math functions.
174
+ ```
175
+ Help: mysh help command summary:
176
+
177
+ The help (or ?) command is used to get either general help about mysh or an
178
+ optional specified topic.
179
+
180
+ If the longer form, help is used, a space is required before the topic. If the
181
+ quick form, ? is used, the space is optional.
182
+
183
+ The available help topics are:
184
+
185
+ General help on mysh.
186
+ ! This help on the history command.
187
+ = Help on ruby expressions.
188
+ ? This help on the help command.
189
+ @ Help on the show command.
190
+ env Help on the show env command.
191
+ gls Help on gls internal mysh command.
192
+ help This help on the help command.
193
+ history This help on the history command.
194
+ kbd Help on mysh keyboard mapping.
195
+ math Help on math functions.
196
+ quick Help on quick commands.
197
+ ruby Help on the show ruby command.
198
+ show Help on the show command.
199
+ {{ Help on mysh handlebars.
200
+ ```
153
201
 
154
202
  #### External commands:
155
203
 
@@ -184,19 +232,25 @@ located at:
184
232
 
185
233
  A survey of the contents of that folder will reveal the nature of these files.
186
234
 
187
- New internal commands may also be added in code via the the add method of the
188
- InternalCommand class of the Mysh module. The code to do this would look
235
+ New internal commands may also be added in code via the the add_action method
236
+ of the InternalCommand class of the Mysh module. The code to do this would look
189
237
  something like this:
190
238
 
191
239
  ```ruby
192
240
  module Mysh
193
- class Action
241
+ class NewCommand < Action
194
242
 
195
- add(command_name, command_description) do |args|
196
- # Action block goes here
243
+ #This method is called when the command is executed.
244
+ def call(args)
197
245
  end
198
246
 
247
+
199
248
  end
249
+
250
+ desc = "A succinct description of what this command does."
251
+ command_name = 'new <item>'
252
+ COMMANDS.add_action(NewCommand.new(command_name, desc))
253
+
200
254
  end
201
255
  ```
202
256
 
@@ -206,16 +260,19 @@ separated with spaces. The command is the first word of this string. For
206
260
  example a command_name of:
207
261
 
208
262
  ```
209
- "cd <dst>"
263
+ "new <item>"
210
264
  ```
211
265
 
212
- will create a command called "cd" with a title of "cd &#60;dst&#62;"
266
+ will create a command called "new" with a title of "new &#60;item&#62;"
213
267
 
214
268
  * command_description is a string or an array of strings that describe the
215
269
  command. This serves as the descriptive help for the command. The help display
216
270
  code handles matters like word wrap automatically.
217
- * The args parameter to the action block is an array of zero or more arguments
218
- that were entered with the command.
271
+
272
+ #### About command args
273
+
274
+ The call method take one parameter called args. The args parameter is an array
275
+ of zero or more arguments that were entered with the command.
219
276
 
220
277
  So if a command is given
221
278
 
@@ -225,28 +282,6 @@ the args array will contain:
225
282
 
226
283
  ["abc", "this is a string", "23", "--launch", "--all"]
227
284
 
228
- #### Adding Command Aliases
229
-
230
- Commands sometimes have more than one possible name. This is supported with
231
- the add_alias method:
232
-
233
- ```ruby
234
- module Mysh
235
- class Action
236
-
237
- add_alias(new_name, old_name)
238
-
239
- end
240
- end
241
- ```
242
- #### Add Method Return Values
243
- Both the add and add_alias methods return the newly created action instance.
244
- This may be useful, for example, if it is desired to add singleton methods to
245
- the action in order to extend functionality.
246
-
247
- Note that when an action is aliased, none of the singleton methods are copied
248
- across and these will have to be regenerated in the new action object.
249
-
250
285
  ## Contributing
251
286
 
252
287
  #### Plan A
@@ -20,7 +20,7 @@ module Mysh
20
20
  setup
21
21
 
22
22
  while @mysh_running do
23
- execute_a_command
23
+ execute_a_command(@exec_host.eval_handlebars(get_command("mysh")))
24
24
  end
25
25
  end
26
26
 
@@ -32,8 +32,8 @@ module Mysh
32
32
  end
33
33
 
34
34
  #Execute a single line of input.
35
- def self.execute_a_command
36
- try_execute_command(@exec_host.eval_handlebars(get_command))
35
+ def self.execute_a_command(str)
36
+ try_execute_command(str)
37
37
 
38
38
  rescue MiniReadlineEOI
39
39
  @mysh_running = false
@@ -17,6 +17,12 @@ module Mysh
17
17
  @exec_binding = mysh_binding
18
18
  end
19
19
 
20
+ #Parse the string and call the action.
21
+ def quick_parse_and_call(str)
22
+ call(Mysh.parse_args(str[1...-1]))
23
+ :action
24
+ end
25
+
20
26
  #Get information about the action.
21
27
  def action_info
22
28
  [@name].concat(@description)
@@ -0,0 +1,35 @@
1
+ Help: About mysh handlebars:
2
+
3
+ In mysh, it is possible to embed snippets of ruby into text files or on the
4
+ command line through the use of handlebars. Handlebars look like this:
5
+
6
+ \{\{ code goes here \}\}
7
+
8
+ Lets see a simple example of putting the result of a calculation into the
9
+ command line:
10
+
11
+ mysh>echo \{\{ (1..10).map {|i| i.to_s}.join(" ") \}\} > foo.txt
12
+ mysh>type foo.txt
13
+ 1 2 3 4 5 6 7 8 9 10
14
+
15
+ Handlebars work by evaluating the ruby code within the \{\{ \}\} sequence in
16
+ the appropriate execution environment. For the command line, this is the same
17
+ environment used for the '=' quick execution command. For example:
18
+
19
+ mysh>=a="A very long string indeed!"
20
+ "A very long string indeed!"
21
+ mysh>echo \{\{ a \}\}
22
+ A very long string indeed!
23
+
24
+ The value returned by expression is coverted to a string (if needed) and then
25
+ inserted in place of the handlebar expression. There are, however, times when
26
+ it is not desired to insert anything in the place of the code snippet. For
27
+ those cases, simply end the expression with a '#' character. For example:
28
+
29
+ mysh>echo \{\{ "not embedded" #\}\} \{\{ "embedded" \}\}
30
+ embedded
31
+
32
+ Finally, it may be that it is desired to embed braces into a text file or
33
+ the command line. In that case precede the brace with a baclslash character
34
+ like: \\{ or \\}
35
+
@@ -0,0 +1,31 @@
1
+ Help: mysh keyboard mappings:
2
+
3
+ The mysh shell uses the mini_readline gem to supports an interactive command
4
+ line experience. The user interface is mapped through the keyboard, based on
5
+ the current operating platform.
6
+
7
+ The keyboard (and alias) mappings are listed below:
8
+
9
+ Editor Action | Windows Key Alias | Mac/Linux Key Alias
10
+ -----------------+--------------------------+---------------------------
11
+ Enter | Enter | Enter
12
+ Left | Left Arrow | Left Arrow, Ctrl-b
13
+ Word Left | Ctrl Left Arrow | Ctrl Left Arrow Alt-b
14
+ Right | Right Arrow | Right Arrow Ctrl-f
15
+ Word Right | Ctrl Right Arrow | Ctrl Right Arrow Alt-f
16
+ Go to start | Home | Home Ctrl-a
17
+ Go to end | End | End Ctrl-E
18
+ Previous History | Up Arrow | Up Arrow Ctrl-r
19
+ Next History | Down Arrow | Down Arrow
20
+ Erase Left | Backspace Ctrl-h | Backspace Ctrl-h
21
+ Erase All Left | | Ctrl-u
22
+ Erase Right | Delete Ctrl-Backspace | Delete Ctrl-Backspace
23
+ Erase All Right | | Ctrl-k
24
+ Erase All | Escape | Ctrl-l
25
+ Auto-complete | Tab Ctrl-i | Tab Ctrl-i
26
+ Quick exit mysh | Ctrl-z | Alt-z
27
+
28
+ Notes:
29
+ Windows keys are aliased through the numeric key pad unless NumLock is on.
30
+ Mac/Linux mappings may use Escape letter if Alt-letter is unavailable.
31
+
@@ -19,19 +19,23 @@ module Mysh
19
19
 
20
20
  end
21
21
 
22
- help = [['', 'General help on mysh.', 'help.txt' ],
23
- ['show', 'Help on the show command.', 'help_show.txt'],
24
- ['@', 'Help on the show command.', 'help_show.txt'],
25
- ['env', 'Help on the show env command.', 'help_env.txt' ],
26
- ['ruby', 'Help on the show ruby command.', 'help_ruby.txt'],
27
- ['math', 'Help on math functions.', 'help_math.txt'],
28
- ['=', 'Help on ruby expressions.', 'help_expr.txt'],
29
- ['quick', 'Help on quick commands.', 'quick.txt' ],
30
- ['gls', 'Help on gls internal mysh command.', 'help_gls.txt' ],
31
- ['!', 'This help on the history command.', 'history.txt' ],
32
- ['history', 'This help on the history command.', 'history.txt' ],
33
- ['help', 'This help on the help command.', 'help_help.txt'],
34
- ['?', 'This help on the help command.', 'help_help.txt']
22
+ #Add help topics here. Don't sweat the order; they get sorted by name.
23
+ # Name Description Help File
24
+ help = [['', 'General help on mysh.', 'help.txt' ],
25
+ ['show', 'Help on the show command.', 'show.txt' ],
26
+ ['@', 'Help on the show command.', 'show.txt' ],
27
+ ['env', 'Help on the show env command.', 'env.txt' ],
28
+ ['ruby', 'Help on the show ruby command.', 'ruby.txt' ],
29
+ ['math', 'Help on math functions.', 'math.txt' ],
30
+ ['=', 'Help on ruby expressions.', 'expr.txt' ],
31
+ ['quick', 'Help on quick commands.', 'quick.txt' ],
32
+ ['gls', 'Help on gls internal mysh command.', 'gls.txt' ],
33
+ ['!', 'This help on the history command.', 'history.txt'],
34
+ ['history', 'This help on the history command.', 'history.txt'],
35
+ ['kbd', 'Help on mysh keyboard mapping.', 'kbd.txt' ],
36
+ ['{{', 'Help on mysh handlebars.', 'hbar.txt' ],
37
+ ['help', 'This help on the help command.', 'h_o_h.txt' ],
38
+ ['?', 'This help on the help command.', 'h_o_h.txt' ]
35
39
  ]
36
40
 
37
41
  help.each do |parms|
@@ -13,7 +13,7 @@ module Mysh
13
13
 
14
14
  #Execute a help command by routing it to a sub-command.
15
15
  #<br>Endemic Code Smells
16
- #* :reek:UtilityFunction
16
+ #* :reek:UtilityFunction :reek:FeatureEnvy
17
17
  def call(args)
18
18
  if args.empty?
19
19
  puts "An item is needed for the show command."
@@ -19,7 +19,7 @@ module Mysh
19
19
  #<br>Endemic Code Smells
20
20
  #* :reek:UtilityFunction
21
21
  def info
22
- [["location", RbConfig.ruby],
22
+ [["location", decorate(RbConfig.ruby)],
23
23
  ["description", RUBY_DESCRIPTION],
24
24
  ["version", RUBY_VERSION],
25
25
  ["patch", RUBY_PATCHLEVEL],
@@ -3,30 +3,18 @@
3
3
  #* mysh/internal/quick.rb -- The mysh internal quick commands.
4
4
  module Mysh
5
5
 
6
- #Try to execute the string as a quick command.
7
- def self.try_execute_quick_command(str)
8
- case str[0]
9
- when '!'
10
- HISTORY_COMMAND.call(parse_args(str[1...-1]))
11
- :history
12
-
13
- when '='
14
- @exec_host.execute(str)
15
- :expression
16
-
17
- when '?'
18
- HELP_COMMAND.call(parse_args(str[1...-1]))
19
- :help
6
+ #A hash of quick command short cuts and their actions.
7
+ QUICK = Hash.new(lambda {|_str| false})
20
8
 
21
- when '@'
22
- SHOW_COMMAND.call(parse_args(str[1...-1]))
23
- :show
9
+ QUICK['!'] = lambda {|str| HISTORY_COMMAND.quick_parse_and_call(str) }
10
+ QUICK['='] = lambda {|str| @exec_host.execute(str); :expression }
11
+ QUICK['?'] = lambda {|str| HELP_COMMAND.quick_parse_and_call(str) }
12
+ QUICK['@'] = lambda {|str| SHOW_COMMAND.quick_parse_and_call(str) }
24
13
 
25
- else
26
- false
27
- end
14
+ #Try to execute the string as a quick command.
15
+ def self.try_execute_quick_command(str)
16
+ QUICK[str[0]].call(str)
28
17
  end
29
18
 
30
-
31
19
  end
32
20
 
@@ -15,18 +15,22 @@ module Mysh
15
15
  end
16
16
 
17
17
  #Get one command from the user.
18
- def self.get_command
19
- initial_input = @input.readline(prompt: 'mysh>')
18
+ def self.get_command(root="")
19
+ initial_input = @input.readline(prompt: root + '>')
20
20
  @input.instance_options[:initial] = ""
21
- get_command_extra(initial_input)
21
+ get_command_extra(initial_input, root)
22
+
23
+ rescue MiniReadlineEOI
24
+ @mysh_running = false
25
+ "\n"
22
26
  end
23
27
 
24
28
  private
25
29
 
26
30
  #Get any continuations of the inputs
27
- def self.get_command_extra(str)
31
+ def self.get_command_extra(str, root)
28
32
  if /\\\s*$/ =~ str
29
- parms = {prompt: 'mysh\\', prefix: str[0] }
33
+ parms = {prompt: root + '\\', prefix: str[0] }
30
34
  get_command_extra($PREMATCH + "\n" + @input.readline(parms))
31
35
  else
32
36
  str
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Mysh
4
4
  #The version string of MY SHell.
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
 
7
7
  #A brief summary of this gem.
8
8
  SUMMARY = "mysh -- a Ruby inspired command line shell."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-20 00:00:00.000000000 Z
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -162,16 +162,18 @@ files:
162
162
  - lib/mysh/internal/actions/exit.rb
163
163
  - lib/mysh/internal/actions/gls.rb
164
164
  - lib/mysh/internal/actions/help.rb
165
+ - lib/mysh/internal/actions/help/env.txt
166
+ - lib/mysh/internal/actions/help/expr.txt
167
+ - lib/mysh/internal/actions/help/gls.txt
168
+ - lib/mysh/internal/actions/help/h_o_h.txt
169
+ - lib/mysh/internal/actions/help/hbar.txt
165
170
  - lib/mysh/internal/actions/help/help.txt
166
- - lib/mysh/internal/actions/help/help_env.txt
167
- - lib/mysh/internal/actions/help/help_expr.txt
168
- - lib/mysh/internal/actions/help/help_gls.txt
169
- - lib/mysh/internal/actions/help/help_help.txt
170
- - lib/mysh/internal/actions/help/help_math.txt
171
- - lib/mysh/internal/actions/help/help_ruby.txt
172
- - lib/mysh/internal/actions/help/help_show.txt
173
171
  - lib/mysh/internal/actions/help/history.txt
172
+ - lib/mysh/internal/actions/help/kbd.txt
173
+ - lib/mysh/internal/actions/help/math.txt
174
174
  - lib/mysh/internal/actions/help/quick.txt
175
+ - lib/mysh/internal/actions/help/ruby.txt
176
+ - lib/mysh/internal/actions/help/show.txt
175
177
  - lib/mysh/internal/actions/help/sub_help.rb
176
178
  - lib/mysh/internal/actions/history.rb
177
179
  - lib/mysh/internal/actions/pwd.rb