mysh 0.1.15 → 0.1.16
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 +4 -4
- data/README.md +41 -10
- data/lib/mysh/expression.rb +0 -2
- data/lib/mysh/internal/action.rb +1 -1
- data/lib/mysh/internal/action_pool.rb +9 -9
- data/lib/mysh/internal/actions/cd.rb +2 -2
- data/lib/mysh/internal/actions/help.txt +11 -26
- data/lib/mysh/internal/actions/help_expr.txt +14 -9
- data/lib/mysh/internal/format.rb +6 -30
- data/lib/mysh/internal/format/bullets.rb +113 -0
- data/lib/mysh/user_input/handlebars.rb +29 -16
- data/lib/mysh/version.rb +1 -1
- data/rakefile.rb +3 -0
- data/tests/my_shell_tests.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 456fdf1833320032c9452e13eeb0c140d84f69e6
|
4
|
+
data.tar.gz: 0590da7cd17f06fe1b428b47026b054f30fce371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d72558e9e315c03ba978cda6ef40cbbfe113bcc995933b2e76ad5744bc22aa5fa50dfa9958d82e65e333293c03f2ff0a1dba5100e5ed1c8edb047a3a0949ee14
|
7
|
+
data.tar.gz: 18d160168fd6aec07cb6b6064f1a0adad97018214ab14dd24592e7c95bc629039a7460889f9c46217fc57c7eafa28b323832df9439c9fe20784356e4dd95b75e
|
data/README.md
CHANGED
@@ -137,6 +137,18 @@ history Display the mysh command history.
|
|
137
137
|
pwd Display the current working directory.
|
138
138
|
quit Exit mysh.
|
139
139
|
```
|
140
|
+
Of note is the command "help help" which provides a list of available topics.
|
141
|
+
|
142
|
+
The help (or ?) command is used to get either general help about mysh
|
143
|
+
or an optional specified topic.
|
144
|
+
|
145
|
+
The available help topics are:
|
146
|
+
|
147
|
+
General help on mysh.
|
148
|
+
= Help on mysh ruby expressions.
|
149
|
+
? Help on mysh help.
|
150
|
+
help Help on mysh help.
|
151
|
+
math Help on mysh math functions.
|
140
152
|
|
141
153
|
#### External commands:
|
142
154
|
|
@@ -164,13 +176,12 @@ Mysh.run
|
|
164
176
|
#### Adding New Commands
|
165
177
|
|
166
178
|
It is possible to add new internal commands to the mysh CLI. This may done
|
167
|
-
manually by depositing the appropriate ruby file in the
|
168
|
-
at:
|
179
|
+
manually by depositing the appropriate ruby file in the actions folder
|
180
|
+
located at:
|
169
181
|
|
170
|
-
<gem_root>/mysh/lib/mysh/
|
182
|
+
<gem_root>/mysh/lib/mysh/internal/actions
|
171
183
|
|
172
|
-
A survey of the contents of that folder will reveal the nature of these
|
173
|
-
command files.
|
184
|
+
A survey of the contents of that folder will reveal the nature of these files.
|
174
185
|
|
175
186
|
New internal commands may also be added in code via the the add method of the
|
176
187
|
InternalCommand class of the Mysh module. The code to do this would look
|
@@ -178,7 +189,7 @@ something like this:
|
|
178
189
|
|
179
190
|
```ruby
|
180
191
|
module Mysh
|
181
|
-
class
|
192
|
+
class Action
|
182
193
|
|
183
194
|
add(command_name, command_description) do |args|
|
184
195
|
# Action block goes here
|
@@ -190,17 +201,37 @@ end
|
|
190
201
|
|
191
202
|
Where:
|
192
203
|
* command_name is the name of the command with optional argument descriptions
|
193
|
-
separated with spaces. The command is the first word of this string.
|
204
|
+
separated with spaces. The command is the first word of this string. For
|
205
|
+
example a command_name of:
|
206
|
+
|
207
|
+
```
|
208
|
+
"cd <dst>"
|
209
|
+
```
|
210
|
+
|
211
|
+
will create a command called "cd" with a title of "cd <dst>"
|
212
|
+
|
194
213
|
* command_description is a string or an array of strings that describe the
|
195
|
-
command.
|
196
|
-
|
214
|
+
command. This serves as the descriptive help for the command. The help display
|
215
|
+
code handles matters like word wrap automatically.
|
216
|
+
* The args parameter to the action block is an array of zero or more arguments
|
217
|
+
that were entered with the command.
|
218
|
+
|
219
|
+
So if a command is given
|
220
|
+
|
221
|
+
command abc "this is a string" 23 --launch --all
|
222
|
+
|
223
|
+
the args array will contain:
|
224
|
+
|
225
|
+
["abc", "this is a string", "23", "--launch", "--all"]
|
226
|
+
|
227
|
+
#### Adding Command Aliases
|
197
228
|
|
198
229
|
Commands sometimes have more than one possible name. This is supported with
|
199
230
|
the add_alias method:
|
200
231
|
|
201
232
|
```ruby
|
202
233
|
module Mysh
|
203
|
-
class
|
234
|
+
class Action
|
204
235
|
|
205
236
|
add_alias(new_name, old_name)
|
206
237
|
|
data/lib/mysh/expression.rb
CHANGED
data/lib/mysh/internal/action.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
#* internal/action_pool.rb -- A managed hash of mysh
|
3
|
+
#* internal/action_pool.rb -- A managed hash of mysh actions.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
#* A managed hash of mysh
|
6
|
+
#* A managed hash of mysh actions.
|
7
7
|
class ActionPool
|
8
8
|
|
9
|
-
#Create a new
|
9
|
+
#Create a new action pool
|
10
10
|
def initialize(&default_action)
|
11
11
|
@pool = {}
|
12
12
|
|
@@ -15,31 +15,31 @@ module Mysh
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
#Get a
|
18
|
+
#Get a action.
|
19
19
|
def [](index)
|
20
20
|
@pool[index]
|
21
21
|
end
|
22
22
|
|
23
|
-
#Add a
|
23
|
+
#Add a action.
|
24
24
|
def add(name, description, &action)
|
25
25
|
split_name = name.split[0] || ""
|
26
26
|
|
27
27
|
@pool[split_name] = Action.new(name, description, &action)
|
28
28
|
end
|
29
29
|
|
30
|
-
#Add an alias for an existing
|
30
|
+
#Add an alias for an existing action.
|
31
31
|
def add_alias(new_name, old_name)
|
32
|
-
unless (
|
32
|
+
unless (action = @pool[old_name])
|
33
33
|
fail "Error adding alias #{new_name} for #{old_name}"
|
34
34
|
end
|
35
35
|
|
36
36
|
split_name = new_name.split[0]
|
37
37
|
|
38
38
|
@pool[split_name] =
|
39
|
-
Action.new(new_name,
|
39
|
+
Action.new(new_name, action.description, &action.action)
|
40
40
|
end
|
41
41
|
|
42
|
-
#Get information on all
|
42
|
+
#Get information on all actions.
|
43
43
|
def actions_info
|
44
44
|
@pool
|
45
45
|
.values
|
@@ -6,8 +6,8 @@ module Mysh
|
|
6
6
|
#* cd.rb -- The mysh internal cd command.
|
7
7
|
class Action
|
8
8
|
#Add the cd command to the library.
|
9
|
-
desc =
|
10
|
-
|
9
|
+
desc = 'Change directory to the optional <dir> parameter ' +
|
10
|
+
'and then display the current working directory.'
|
11
11
|
|
12
12
|
COMMANDS.add('cd <dir>', desc) do |args|
|
13
13
|
begin
|
@@ -1,42 +1,27 @@
|
|
1
1
|
mysh (MY ruby SHell) version: {{ Mysh::VERSION }}
|
2
2
|
|
3
3
|
The mysh is a shell program inspired by the Ruby programming language in the
|
4
|
-
same way the csh was inspired by the "C" programming language.
|
5
|
-
was already widely in use so it was mysh for some extra ego.
|
4
|
+
same way the csh was inspired by the "C" programming language.
|
6
5
|
|
7
6
|
In mysh, commands fall into one of three broad categories. There are:
|
8
7
|
|
9
|
-
1)
|
8
|
+
1) "=" expressions: Any line beginning with an "=" will be evaluated as a Ruby
|
9
|
+
language expression. For more see the '? =' or '? math' commands.
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
debugging and super-calculator environment.
|
14
|
-
|
15
|
-
For more information on ruby expressions use the 'help =' command.
|
16
|
-
|
17
|
-
Note: This environment includes support for advanced mathematical operations.
|
18
|
-
For more information on this feature, use the 'help math' command.
|
19
|
-
|
20
|
-
2) Internal mysh commands:
|
21
|
-
|
22
|
-
Internal commands are processed within mysh itself. Any command that matches
|
23
|
-
the name of an internal command is processed internally by mysh.
|
24
|
-
|
25
|
-
The following set of commands are supported:
|
11
|
+
2) Internal mysh commands are processed within mysh itself. The following set
|
12
|
+
of commands are supported:
|
26
13
|
|
27
14
|
{{ format_items(Mysh::COMMANDS.actions_info).join("\n") }}
|
28
15
|
|
29
|
-
3)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
If the command has a '.rb' extension, it is executed by the appropriate ruby
|
35
|
-
interpreter. So the command "myfile.rb" is executed as
|
16
|
+
3) All other commands are executed by the system using the standard shell or
|
17
|
+
the appropriate ruby interpreter. If the command has a '.rb' extension, it
|
18
|
+
is executed by the appropriate ruby interpreter. So the command "myfile.rb"
|
19
|
+
is executed as:
|
36
20
|
|
37
|
-
|
21
|
+
"{{ RbConfig.ruby }} myfile.rb"
|
38
22
|
|
39
23
|
Note: If an internal command has the same name as an external command, adding a
|
40
24
|
leading space will force the use of the external command.
|
41
25
|
|
26
|
+
Help on help: For a list of all help topics see the '? ?' command.
|
42
27
|
|
@@ -1,17 +1,20 @@
|
|
1
1
|
mysh Ruby expression support summary:
|
2
2
|
|
3
|
-
All command lines that begin with
|
4
|
-
expressions. Lines ending with a backslash character ("\") are continued on the
|
5
|
-
next line. The prompt changes to "mysh\" to indicate that this is going on. The
|
6
|
-
command is NOT actually processed until a line with NO trailing backslash is
|
7
|
-
entered.
|
3
|
+
All command lines that begin with = are evaluated as Ruby expressions.
|
8
4
|
|
9
|
-
|
5
|
+
Notes:
|
10
6
|
|
11
|
-
|
12
|
-
|
7
|
+
Lines ending with a \\ are continued on the next line. The prompt changes to
|
8
|
+
mysh\\ to indicate that this is going on. The command is NOT actually processed
|
9
|
+
until a line with NO trailing \\ is entered.
|
13
10
|
|
14
|
-
|
11
|
+
The results of the expression are displayed using the pretty-print facility
|
12
|
+
except for nil (shows as blank).
|
13
|
+
|
14
|
+
Auto-complete always places any file names in quotes so they can be used as
|
15
|
+
string parameters.
|
16
|
+
|
17
|
+
A few special methods exist:
|
15
18
|
|
16
19
|
=reset Reset the execution environment to the default state.
|
17
20
|
=result Returns the result of the previous expression.
|
@@ -19,3 +22,5 @@ A few noteworthy special methods exist:
|
|
19
22
|
=vls "mask" List modules with version info. The optional mask string value is
|
20
23
|
used to filter for modules containing that string.
|
21
24
|
|
25
|
+
Also included are a number of math methods. See '? math' for more on these.
|
26
|
+
|
data/lib/mysh/internal/format.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require_relative 'format/bullets'
|
4
|
+
|
3
5
|
#The mysh internal command class level report formatting.
|
4
6
|
class Object
|
5
7
|
|
@@ -7,41 +9,15 @@ class Object
|
|
7
9
|
|
8
10
|
#Display an array of items.
|
9
11
|
def display_items(items)
|
10
|
-
|
12
|
+
items.puts_mysh_bullets
|
11
13
|
puts
|
12
14
|
end
|
13
15
|
|
14
16
|
#Format an array of items.
|
15
17
|
#<br>Endemic Code Smells
|
16
|
-
#* :reek:FeatureEnvy
|
17
|
-
def format_items(items
|
18
|
-
|
19
|
-
tag_width = items.max_by {|item| item[0].length}[0].length + 1
|
20
|
-
|
21
|
-
#Display the information.
|
22
|
-
items.each {|item| format_item(item, buffer, tag_width) }
|
23
|
-
|
24
|
-
buffer
|
25
|
-
end
|
26
|
-
|
27
|
-
#Display one item.
|
28
|
-
def display_item(item, tag_width=nil)
|
29
|
-
puts format_item(item, [], tag_width)
|
30
|
-
puts
|
31
|
-
end
|
32
|
-
|
33
|
-
#Format one item.
|
34
|
-
#<br>Endemic Code Smells
|
35
|
-
#* :reek:UtilityFunction
|
36
|
-
def format_item(item, buffer=[], tag_width)
|
37
|
-
tag = item[0]
|
38
|
-
|
39
|
-
item[1].each do |detail|
|
40
|
-
buffer << "#{tag.ljust(tag_width)} #{detail}"
|
41
|
-
tag = ""
|
42
|
-
end
|
43
|
-
|
44
|
-
buffer
|
18
|
+
#* :reek:FeatureEnvy :reek:UtilityFunction
|
19
|
+
def format_items(items)
|
20
|
+
items.mysh_bulletize
|
45
21
|
end
|
46
22
|
|
47
23
|
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* internal/format/bullets.rb - Print out bullet points.
|
4
|
+
module Mysh
|
5
|
+
|
6
|
+
#A class to display data in bullet points.
|
7
|
+
class BulletPoints
|
8
|
+
|
9
|
+
#Assume an 80 column working area.
|
10
|
+
PAGE_WIDTH = 80
|
11
|
+
|
12
|
+
#Prepare a blank slate.
|
13
|
+
def initialize
|
14
|
+
@bullet_data = []
|
15
|
+
end
|
16
|
+
|
17
|
+
#Add an item to this page.
|
18
|
+
#<br>Endemic Code Smells
|
19
|
+
#* :reek:FeatureEnvy :reek:TooManyStatements
|
20
|
+
def add(raw_bullet = "*", *raw_item)
|
21
|
+
|
22
|
+
if raw_item.empty?
|
23
|
+
bullet = ["*"]
|
24
|
+
items = raw_bullet.in_array
|
25
|
+
else
|
26
|
+
bullet = [raw_bullet]
|
27
|
+
items = raw_item.in_array
|
28
|
+
end
|
29
|
+
|
30
|
+
items.each_index do |index|
|
31
|
+
@bullet_data << [(bullet[index] || "").to_s, items[index].to_s]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#Render the page as an array of strings.
|
36
|
+
def render
|
37
|
+
@key_length, results = get_key_length, []
|
38
|
+
|
39
|
+
@bullet_data.each do |key, item|
|
40
|
+
results.concat(render_bullet(key, item))
|
41
|
+
end
|
42
|
+
|
43
|
+
@bullet_data = []
|
44
|
+
results
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
#How large is the largest bullet?
|
50
|
+
def get_key_length
|
51
|
+
(@bullet_data.max_by {|line| line[0].length})[0].length
|
52
|
+
end
|
53
|
+
|
54
|
+
#Render one bullet point.
|
55
|
+
#<br>Endemic Code Smells
|
56
|
+
#* :reek:DuplicateMethodCall :reek:TooManyStatements
|
57
|
+
def render_bullet(key, item)
|
58
|
+
result, pass_one = [], true
|
59
|
+
input = item.split(' ').each
|
60
|
+
temp = key.ljust(len = @key_length)
|
61
|
+
|
62
|
+
loop do
|
63
|
+
word = ' ' + input.next
|
64
|
+
|
65
|
+
while len >= PAGE_WIDTH
|
66
|
+
result << temp.slice!(0, PAGE_WIDTH - 1)
|
67
|
+
temp = blank_key + ' ' + temp
|
68
|
+
len = temp.length
|
69
|
+
end
|
70
|
+
|
71
|
+
if ((len += word.length) >= PAGE_WIDTH) && !pass_one
|
72
|
+
result << temp
|
73
|
+
temp = blank_key + word
|
74
|
+
len = temp.length
|
75
|
+
else
|
76
|
+
temp << word
|
77
|
+
pass_one = false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
result << temp
|
82
|
+
end
|
83
|
+
|
84
|
+
#Generate a blank bullet key
|
85
|
+
def blank_key
|
86
|
+
' ' * @key_length
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
#Bullet point support in the Array class.
|
94
|
+
class Array
|
95
|
+
#Print out the array as bullet points.
|
96
|
+
def puts_mysh_bullets
|
97
|
+
puts mysh_bulletize
|
98
|
+
end
|
99
|
+
|
100
|
+
#Convert the array to strings with bullet points.
|
101
|
+
#<br>
|
102
|
+
#* An array of arrays of strings
|
103
|
+
def mysh_bulletize
|
104
|
+
builder = Mysh::BulletPoints.new
|
105
|
+
|
106
|
+
self.each do |pair|
|
107
|
+
builder.add(*pair)
|
108
|
+
end
|
109
|
+
|
110
|
+
builder.render
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
@@ -3,29 +3,42 @@
|
|
3
3
|
#* user_input/handlebars.rb -- Handlebar embedded ruby support.
|
4
4
|
class Object
|
5
5
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
result = instance_eval(code = match[2...-2])
|
14
|
-
|
15
|
-
str = pre_match + (result unless code.end_with?("#")).to_s + post_match
|
16
|
-
end
|
6
|
+
#Show a file with embedded ruby handlebars.
|
7
|
+
#<br>Note:
|
8
|
+
#The message receiver is the evaluation host for the handlebar code.
|
9
|
+
def show_handlebar_file(name)
|
10
|
+
puts eval_handlebar_file(name)
|
11
|
+
rescue Interrupt, StandardError, ScriptError => err
|
12
|
+
puts "Error in file: #{name}\n#{err.class}: #{err}"
|
17
13
|
end
|
18
14
|
|
19
15
|
#Expand a file with embedded ruby handlebars.
|
16
|
+
#<br>Note:
|
17
|
+
#The message receiver is the evaluation host for the handlebar code.
|
20
18
|
def eval_handlebar_file(name)
|
21
19
|
eval_handlebars(IO.read(name))
|
22
20
|
end
|
23
21
|
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
#Process a string with backslash quotes and code embedded in handlebars.
|
23
|
+
#<br>Note:
|
24
|
+
#The message receiver is the evaluation host for the handlebar code.
|
25
|
+
def eval_handlebars(str)
|
26
|
+
do_process_handlebars(str).gsub(/\\\S/) {|found| found[1]}
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
#Process a string with code embedded in handlebars.
|
32
|
+
#<br>Note:
|
33
|
+
#The message receiver is the evaluation host for the handlebar code.
|
34
|
+
def do_process_handlebars(str)
|
35
|
+
str.gsub(/{{.*?}}/m) do |match|
|
36
|
+
code = match[2...-2]
|
37
|
+
silent = code.end_with?("#")
|
38
|
+
result = instance_eval(code)
|
39
|
+
|
40
|
+
(result unless silent).to_s
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
end
|
data/lib/mysh/version.rb
CHANGED
data/rakefile.rb
CHANGED
@@ -12,6 +12,9 @@ RDoc::Task.new do |rdoc|
|
|
12
12
|
#List out all the files to be documented.
|
13
13
|
rdoc.rdoc_files.include("lib/**/*.rb", "license.txt")
|
14
14
|
|
15
|
+
#Make all access levels visible.
|
16
|
+
rdoc.options << '--visibility' << 'private'
|
17
|
+
|
15
18
|
#Set a title.
|
16
19
|
rdoc.options << '--title' << 'My Shell Gem Internals'
|
17
20
|
end
|
data/tests/my_shell_tests.rb
CHANGED
@@ -39,6 +39,9 @@ class MyShellTester < Minitest::Test
|
|
39
39
|
|
40
40
|
assert_equal("ABC", eval_handlebars("{{ 'ABC' }}"))
|
41
41
|
assert_equal("", eval_handlebars("{{ 'ABC' #}}"))
|
42
|
+
|
43
|
+
assert_equal("{{ 'ABC' }}", eval_handlebars("\\{\\{ 'ABC' \\}\\}"))
|
44
|
+
assert_equal("{{A}}", eval_handlebars("{{ '{'+'{A}'+'}' }}"))
|
42
45
|
end
|
43
46
|
|
44
47
|
end
|
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.1.
|
4
|
+
version: 0.1.16
|
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-
|
11
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/mysh/internal/actions/history.rb
|
169
169
|
- lib/mysh/internal/decorate.rb
|
170
170
|
- lib/mysh/internal/format.rb
|
171
|
+
- lib/mysh/internal/format/bullets.rb
|
171
172
|
- lib/mysh/internal/manage.rb
|
172
173
|
- lib/mysh/user_input.rb
|
173
174
|
- lib/mysh/user_input/handlebars.rb
|
@@ -200,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
201
|
version: '0'
|
201
202
|
requirements: []
|
202
203
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.2.
|
204
|
+
rubygems_version: 2.2.3
|
204
205
|
signing_key:
|
205
206
|
specification_version: 4
|
206
207
|
summary: mysh -- a Ruby inspired command shell.
|