mysh 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be90389579f158cf24d6bc6865749b44cc9f21b8
4
+ data.tar.gz: dc61d9d021c118448d29cd22ddff718c69834965
5
+ SHA512:
6
+ metadata.gz: 3e7196157f03f97324b95c3b1d4d1e46b619b085517403e918780e5a433332f8cae11ba9f39b5d8c0508cd875feae1451afc43412fbe0f97a3fe093460310c51
7
+ data.tar.gz: 9594ca2ee74430d85e7a068354b5062c3569adc4ca86a24225186ec66e0a35b0dcfb46cd8f070f8e4e122460f68bbab006679028b7f1267b9c87419bccdb5443
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.bat
2
+ *.zip
3
+ *.tmp
4
+ *.gem
5
+ *.rbc
6
+ /.bundle/
7
+ /.yardoc
8
+ /Gemfile.lock
9
+ /_yardoc/
10
+ /coverage/
11
+ /doc/
12
+ /pkg/
13
+ /spec/reports/
14
+ /tmp/
15
+ rdoc
16
+ tmp
17
+ temp.txt
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mysh.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Peter Camilleri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Mysh
2
+
3
+ Inspired by the excellent article "Writing a Shell in 25 Lines of Ruby Code"
4
+ found at (http://www.blackbytes.info/2016/07/writing-a-shell-in-ruby/) I
5
+ thought it would be fun to experiment with that concept and see if it could
6
+ be taken further.
7
+
8
+ Many years ago, a popular shell program was modeled after
9
+ the 'C' programming language. It went by the csh for C-shell (by the C shore :-)
10
+ Instead of 'C', my shell would be based on Ruby (were you shocked?)! The
11
+ obvious name rsh for Ruby-shell was already in use by the Remote-shell. So,
12
+ given the limited scope of this effort, and not wanting to do a lot of typing
13
+ all the time, I chose the name mysh for My-shell.
14
+
15
+ Since that name was available, it would seem that no one had yet written a
16
+ shell program at this level of narcissism.
17
+
18
+ The mysh is available as both a stand-alone CLI program and for use as a
19
+ command shell within Ruby applications and Rails web sites.
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'mysh'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install mysh
36
+
37
+ ## Usage
38
+
39
+ TODO: Write usage instructions here
40
+
41
+ ## Contributing
42
+
43
+ #### Plan A
44
+
45
+ 1. Fork it ( https://github.com/PeterCamilleri/mysh/fork )
46
+ 2. Switch to the development branch ('git branch development')
47
+ 3. Create your feature branch ('git checkout -b my-new-feature')
48
+ 4. Commit your changes ('git commit -am "Add some feature"')
49
+ 5. Push to the branch ('git push origin my-new-feature')
50
+ 6. Create new Pull Request
51
+
52
+ #### Plan B
53
+
54
+ Go to the GitHub repository at (https://github.com/PeterCamilleri/mysh) and
55
+ raise an issue calling attention to some aspect that could use some TLC or a
56
+ suggestion or an idea.
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+
3
+ #* commands/exit.rb -- The mysh internal exit command.
4
+ module Mysh
5
+
6
+ #* exit.rb -- The mysh internal exit command.
7
+ class InternalCommand
8
+ #Add the exit command to the library.
9
+ add(self.new('exit', 'exit mysh.') do |args|
10
+ raise MiniReadlineEOI
11
+ end)
12
+
13
+ add_alias('quit', 'exit')
14
+ end
15
+ end
16
+
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ #* internal.rb -- mysh internal command instance data and methods.
4
+ module Mysh
5
+
6
+ #The mysh internal command instance data and methods.
7
+ class InternalCommand
8
+ #The name of the command.
9
+ attr_reader :name
10
+
11
+ #The description of the command.
12
+ attr_reader :description
13
+
14
+ #The action of the command.
15
+ attr_reader :action
16
+
17
+ #Setup an internal command
18
+ def initialize(name, description, &action)
19
+ @name = name
20
+ @description = description
21
+ @action = action
22
+ end
23
+
24
+ #Execute the command.
25
+ def execute(args)
26
+ @action.call(args)
27
+ end
28
+
29
+ #Get information about the command.
30
+ def info
31
+ [@name, @description]
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+
3
+ #* internal/klass.rb -- mysh internal command class level data and methods.
4
+ module Mysh
5
+
6
+ #The mysh internal command class level data and methods.
7
+ class InternalCommand
8
+
9
+ #Set up the command library hash.
10
+ @commands = {}
11
+
12
+ class << self
13
+ #The command library, a hash.
14
+ attr_reader :commands
15
+ end
16
+
17
+ #Add a command to the command library.
18
+ def self.add(command)
19
+ @commands[command.name] = command
20
+ end
21
+
22
+ #Add an alias for an existing command.
23
+ def self.add_alias(new_name, old_name)
24
+ unless (command = @commands[old_name])
25
+ fail "Error adding alias #{new_name} for #{old_name}"
26
+ end
27
+
28
+ @commands[new_name] = new(new_name,
29
+ command.description,
30
+ &command.action)
31
+ end
32
+
33
+ #Execute an internal command
34
+ def self.execute(str)
35
+ args = str.split
36
+
37
+ if (command = @commands[args[0]])
38
+ command.execute(args[1..-1])
39
+ true
40
+ else
41
+ false
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+
3
+ require_relative 'internal/klass.rb'
4
+ require_relative 'internal/instance.rb'
5
+
6
+ #Load up the commands!
7
+ Dir[File.dirname(__FILE__) + '/commands/*.rb'].each {|file| require file }
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+
3
+ module Mysh
4
+ #The version string of MY SHell.
5
+ VERSION = "0.0.1"
6
+
7
+ #A brief summary of this gem.
8
+ SUMMARY = "mysh -- a Ruby inspired command shell"
9
+ end
data/lib/mysh.rb ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ # mysh -- MY SHell -- a Ruby/Rails inspired command shell.
4
+
5
+ #Use the mini_readline gem but make sure that it does
6
+ #not interfere with the standard readline library.
7
+ $no_alias_read_line_module = true
8
+ require "mini_readline"
9
+
10
+ require_relative "mysh/internal"
11
+ require_relative "mysh/version"
12
+
13
+ #The MY SHell module. A container for its functionality.
14
+ module Mysh
15
+
16
+ class << self
17
+ #The input text source.
18
+ attr_reader :input
19
+ end
20
+
21
+ #The actual shell method.
22
+ def self.do_mysh
23
+ @input = MiniReadline::Readline.new(history: true, eoi_detect: true)
24
+
25
+ loop do
26
+ input = @input.readline
27
+ InternalCommand.execute(input) || system(input)
28
+ end
29
+
30
+ rescue MiniReadlineEOI
31
+ end
32
+
33
+ end
34
+
35
+ #Some test code to run a shell if this file is run directly.
36
+ if __FILE__ == $0
37
+ Mysh.do_mysh
38
+ end
data/mysh.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mysh/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mysh"
8
+ spec.version = Mysh::VERSION
9
+ spec.authors = ["Peter Camilleri"]
10
+ spec.email = ["peter.c.camilleri@gmail.com"]
11
+
12
+ spec.summary = Mysh::SUMMARY
13
+ spec.description = "mysh -- a Ruby inspired command shell " +
14
+ "for CLI and application use.[WIP]"
15
+ spec.homepage = "http://teuthida-technologies.com/"
16
+
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = '>=1.9.3'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency 'reek', "~> 3.0"
29
+ spec.add_development_dependency 'minitest', "~> 5.7"
30
+ spec.add_development_dependency 'minitest_visible', ">= 0.1.1"
31
+ spec.add_development_dependency 'rdoc', "~> 4.0.1"
32
+
33
+ spec.add_runtime_dependency 'mini_readline', ">= 0.5.2"
34
+ end
data/rakefile.rb ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env rake
2
+ # coding: utf-8
3
+
4
+ require 'rake/testtask'
5
+ require 'rdoc/task'
6
+ require "bundler/gem_tasks"
7
+
8
+ #Generate internal documentation with rdoc.
9
+ RDoc::Task.new do |rdoc|
10
+ rdoc.rdoc_dir = "rdoc"
11
+
12
+ #List out all the files to be documented.
13
+ rdoc.rdoc_files.include("lib/**/*.rb", "license.txt", "README.md")
14
+
15
+ #Set a title.
16
+ rdoc.options << '--title' << 'My Shell Gem Internals'
17
+ end
18
+
19
+ #Run the mini_readline unit test suite.
20
+ Rake::TestTask.new do |t|
21
+ #List out all the test files.
22
+ t.test_files = FileList['tests/**/*.rb']
23
+ t.verbose = false
24
+ end
25
+
26
+ desc "Run a scan for smelly code!"
27
+ task :reek do |t|
28
+ `reek --no-color lib > reek.txt`
29
+ end
30
+
31
+ desc "What version of mine_readline is this?"
32
+ task :vers do |t|
33
+ puts
34
+ puts "mysh (My Shell) version = #{Mysh::VERSION}"
35
+ end
data/reek.txt ADDED
@@ -0,0 +1 @@
1
+ 0 total warnings
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/mysh'
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
6
+ require 'minitest_visible'
7
+
8
+ #Test the monkey patches applied to the Object class.
9
+ class MyShellTester < Minitest::Test
10
+
11
+ #Track mini-test progress.
12
+ include MinitestVisible
13
+
14
+ def test_that_module_entities_exists
15
+ assert_equal(Module, Mysh.class)
16
+ assert_equal(Class, Mysh::InternalCommand.class)
17
+ end
18
+
19
+ def test_for_internal_commands
20
+ assert(Mysh::InternalCommand.commands['exit'], "The exit command is missing.")
21
+ assert(Mysh::InternalCommand.commands['quit'], "The quit command is missing.")
22
+
23
+ assert_raises { Mysh::InternalCommand.add_alias('blam', 'shazzam') }
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mysh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Camilleri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: reek
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest_visible
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.0.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: mini_readline
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.5.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.5.2
111
+ description: mysh -- a Ruby inspired command shell for CLI and application use.[WIP]
112
+ email:
113
+ - peter.c.camilleri@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - lib/mysh.rb
123
+ - lib/mysh/commands/exit.rb
124
+ - lib/mysh/internal.rb
125
+ - lib/mysh/internal/instance.rb
126
+ - lib/mysh/internal/klass.rb
127
+ - lib/mysh/version.rb
128
+ - mysh.gemspec
129
+ - rakefile.rb
130
+ - reek.txt
131
+ - tests/my_shell_tests.rb
132
+ homepage: http://teuthida-technologies.com/
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 1.9.3
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.2.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: mysh -- a Ruby inspired command shell
156
+ test_files: []
157
+ has_rdoc: