cmdr 0.3.4 → 0.4.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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/cmdr.rb +62 -123
  5. metadata +24 -50
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c85785a4bdc460cf48eaa5edd2a730b4c69ccd6
4
- data.tar.gz: 70d9325dd394e0f4721f107070c79ea09f7def43
3
+ metadata.gz: 1cc9c9e0179e5ee5cd891cb329c477c5895279f2
4
+ data.tar.gz: 4777f73a93902ce20cb4cb70ceb0ccd9833470a7
5
5
  SHA512:
6
- metadata.gz: db8c7fb892001b7920f132ff60639797f908ca8f4b561d5f7e5c788f4b44e14d6598ac26df7288b80fd1e8086d56cc4252f096f35bd51f0c8d87888b695fb9fb
7
- data.tar.gz: 72178ab86cb5afd30871eda7f1ffcd90870ccbfd7d50f6ccd593b5f1253eb4db222ee30998892b2c87b6183e32b91e305ee5fd0f6c10b7d8de61bb636e9d3193
6
+ metadata.gz: 4d519009145bd2756dd2c36ba30c07f237800f88c7bb1bedea656cd215ee4625b53698655af0c6e3d8d0a8f368a294cb5a08792ea86e7efc49db430ec4ae1976
7
+ data.tar.gz: 0cbe2c292533d70314783671ea45172b76c208a6492d583ea38ef3ceebbfba6e0324d383f2ad0609546471d8d649761c1f9779c0850ae5de513dd00ccc5f9f0d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/cmdr.rb CHANGED
@@ -1,152 +1,91 @@
1
- #!/uar/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
- #file: cmdr.rb
3
+ # file: cmdr.rb
4
4
 
5
- require 'builder'
6
- require 'rscript'
7
- require 'rexml/document'
8
- include REXML
9
5
 
10
6
  class Cmdr
11
7
 
12
- def initialize(opt={}, app_mgr=nil)
13
-
14
- opt[:public].merge!({
15
- user:
16
- {'-1' =>
17
- {
18
- history:
19
- {list: [], index: []}
20
- }
21
- }
22
- })
23
-
24
- @v = opt[:public]
25
- @@app = app_mgr
8
+ def initialize()
26
9
 
27
- super()
28
- end
10
+ @linebuffer = ''
11
+ @history = []
12
+ @out = []
29
13
 
30
-
31
- def run_cmd(raw_command, user_id='-1', bottom_up_display=true)
14
+ end
32
15
 
33
- input_string = raw_command.clone
16
+ def input(c, enter: "\r", backspace: "\u007F", arrowup: :arrow_up)
34
17
 
35
- command, options_string = raw_command[/\w+/], ($').strip
18
+ key = c
36
19
 
20
+ reveal(c)
37
21
 
38
- if @v[:alias].has_key? command then
39
- command, options_string2 = @v[:alias][command][/\w+/], ($').strip
40
- options_string = options_string2 + ' '+ options_string
41
- elsif @v[:user][user_id][:alias].has_key? command then
42
- command, options_string2 = @v[:user][user_id][:alias][command][/\w+/], ($').strip
43
- options_string = options_string2 + ' '+ options_string
44
- end
45
-
46
- # save the command to history
47
- unless raw_command[/arrowup|arrowdown/] then
48
- @v[:user][user_id][:history][:list] << raw_command
49
- @v[:user][user_id][:history][:index] = -1
50
- end
51
-
52
- raw_args = options_string.gsub(/\".[^\|\'"]+["']/) {|x| x.gsub(/\s/,'%20')}.split(/\s/)\
53
- .map {|x| x.gsub(/%20/,' ').sub(/\"(.*)\"/,'\1')}
54
- rs = RScript.new()
55
- code, args = rs.read(raw_args)
56
-
57
- @user_id = user_id unless user_id == '-1'
58
- doc = Document.new eval(code)
59
-
60
- node = XPath.first(doc.root, 'summary/javascript')
61
- job_with_js = ''
22
+ @out << case key
23
+ when enter
24
+
25
+ command = @linebuffer
26
+
27
+ @history << command
28
+
29
+ if @linebuffer.length < 1 then
30
+ return clear_cli()
31
+ end
32
+
33
+ result = yield(@linebuffer)
34
+
35
+ if result then
36
+ display_output("\n" + result)
37
+ else
38
+ display_output 'command not found >> ' + @linebuffer.inspect
39
+ end
62
40
 
63
- if node then
64
- job_with_js = node.text.to_s
65
- node.parent.delete node
66
- end
41
+ @linebuffer = ''
42
+ clear_cli()
67
43
 
68
- if XPath.first(doc.root, "records/*") then
69
- r = XPath.match(doc.root, 'records/*').map do |node|
70
- nodes = XPath.match(node, '*')
71
- if nodes.length > 1 then
72
- item_details = nodes.map do |x|
73
- t = x.cdatas.length > 0 ? x.cdatas.join.strip : x.text.to_s.strip
74
- "<strong>%s</strong>: %s" % [x.name, t]
75
- end
76
- else
77
- item_details = nodes.map do |x|
78
- x.cdatas.length > 0 ? x.cdatas.join.strip : x.text.to_s.strip
79
- end
80
- end
81
- "<ul><li>%s</li></ul>" % item_details.join("</li><li>")
82
- end
83
- out = "<ul><li>%s</li></ul>" % r.join("</li><li>")
44
+ when backspace
45
+ @linebuffer.chop!
46
+ cli_update()
47
+ when arrowup
48
+ old_command = @history.last
49
+ @linebuffer = old_command
50
+ cli_update old_command
84
51
  else
85
- text1 = XPath.first(doc.root, 'summary/title/text() | summary/to_s/text()')
86
- out = REXML::Text::unnormalize(text1.to_s).gsub(/"/,'&#34;')
87
- end
88
52
 
89
- javascript = []
90
- javascript << (bottom_up_display == true ? listmite(out) : listite(out))
91
- javascript << job_with_js
92
-
93
- xml = Builder::XmlMarkup.new( :target => buffer='', :indent => 2 )
94
- xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
95
- xml.result do
96
- xml.summary do
97
- xml.status 'success'
98
- xml.script {xml.cdata!(javascript.join("\n"))}
99
- xml.output r.to_s
53
+ if key.length < 2 then
54
+
55
+ @linebuffer << key
56
+ key
100
57
  end
101
- xml.records
58
+
102
59
  end
103
60
 
104
- buffer
61
+ end
105
62
 
63
+ # display the cli banner upon initialisation
64
+ #
65
+ def cli_banner()
66
+ print "> "
106
67
  end
107
68
 
108
69
  protected
109
-
110
- def listite(out)
111
- "
112
- olist = document.getElementById('list');
113
- ocontent = document.getElementById('content');
114
- oli = document.createElement('li');
115
-
116
- oli.innerHTML = \"#{out.gsub(/\r|\n/,"").gsub(/"/,'&#34;')}\";
117
- ocontent.insertBefore(oli, ocontent.firstChild);
118
-
119
- olist.scrollTop = olist.scrollHeight;
120
-
121
- ocommandInput = document.getElementById('user_input');
122
- ocommandInput.value = '';
123
- "
70
+
71
+ # display the current input
72
+ #
73
+ def cli_update(s='')
74
+ print s
124
75
  end
125
76
 
126
- def listmite(out)
127
- "
128
- ocontent = document.getElementById('content');
129
- oli = document.createElement('li');
130
-
131
- oli.innerHTML = \"#{out.gsub(/\r|\n/,"").gsub(/"/,'&#34;')}\";
132
- ocontent.appendChild(oli);
133
- olist.scrollTop = olist.scrollHeight;
77
+ alias clear_cli cli_update
134
78
 
135
- ocommandInput = document.getElementById('user_input');
136
- ocommandInput.value = '';
137
- "
138
- end
139
-
140
- def run_rscript(rsf_url, jobs, arg='')
141
- ajobs = jobs.split(/\s/)
142
- args = [rsf_url, ajobs, arg].flatten
143
- RScript.new().read(args)
79
+ # display the output
80
+ #
81
+ def display_output(s='')
82
+ print s
144
83
  end
145
84
 
146
- def run_script(url, jobs, qargs='')
147
- result, args = run_rscript(url, jobs, qargs)
148
- eval(result)
85
+ # display the key pressed
86
+ #
87
+ def reveal(c)
88
+ print c
149
89
  end
150
-
151
- end
152
90
 
91
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmdr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,55 +10,29 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDRDCCAiygAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
14
  YXN0ZXIxHjAcBgoJkiaJk/IsZAEZ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n
32
+ fduXC3tBaNX+gQ==
31
33
  -----END CERTIFICATE-----
32
- date: 2013-07-27 00:00:00.000000000 Z
33
- dependencies:
34
- - !ruby/object:Gem::Dependency
35
- name: builder
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- type: :runtime
42
- prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- - !ruby/object:Gem::Dependency
49
- name: rscript
50
- requirement: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :runtime
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
34
+ date: 2016-10-30 00:00:00.000000000 Z
35
+ dependencies: []
62
36
  description:
63
37
  email: james@r0bertson.co.uk
64
38
  executables: []
@@ -76,17 +50,17 @@ require_paths:
76
50
  - lib
77
51
  required_ruby_version: !ruby/object:Gem::Requirement
78
52
  requirements:
79
- - - '>='
53
+ - - ">="
80
54
  - !ruby/object:Gem::Version
81
- version: '0'
55
+ version: 2.1.2
82
56
  required_rubygems_version: !ruby/object:Gem::Requirement
83
57
  requirements:
84
- - - '>='
58
+ - - ">="
85
59
  - !ruby/object:Gem::Version
86
60
  version: '0'
87
61
  requirements: []
88
62
  rubyforge_project:
89
- rubygems_version: 2.0.0.rc.2
63
+ rubygems_version: 2.5.1
90
64
  signing_key:
91
65
  specification_version: 4
92
66
  summary: cmdr
metadata.gz.sig CHANGED
Binary file