Floppy-amee 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/ameesh +25 -1
  2. data/lib/amee.rb +2 -2
  3. data/lib/amee/shell.rb +30 -27
  4. metadata +4 -4
data/bin/ameesh CHANGED
@@ -2,4 +2,28 @@
2
2
 
3
3
  irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
4
4
 
5
- exec "#{irb_name} -r rubygems -r amee/shell --simple-prompt"
5
+ require 'optparse'
6
+ # Command-line options - get username, password, and server
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ opts.on("-u USERNAME", "AMEE username") do |u|
10
+ options[:username] = u
11
+ end
12
+ opts.on("-p PASSWORD", "AMEE password") do |p|
13
+ options[:password] = p
14
+ end
15
+ opts.on("-s SERVER", "AMEE server") do |s|
16
+ options[:server] = s
17
+ end
18
+ end.parse!
19
+
20
+ # Set environment variables for irb
21
+ ENV['AMEE_SERVER'] = options[:server]
22
+ ENV['AMEE_USERNAME'] = options[:username]
23
+ ENV['AMEE_PASSWORD'] = options[:password]
24
+
25
+ if options[:server].nil? || options[:username].nil? || options[:password].nil?
26
+ puts "Please provide connection details. Run 'ameesh --help' for details."
27
+ else
28
+ exec "#{irb_name} -r rubygems -r amee/shell --simple-prompt"
29
+ end
data/lib/amee.rb CHANGED
@@ -10,8 +10,8 @@ module AMEE
10
10
 
11
11
  module VERSION #:nodoc:
12
12
  MAJOR = 0
13
- MINOR = 0
14
- TINY = 5
13
+ MINOR = 1
14
+ TINY = 0
15
15
  STRING = [MAJOR, MINOR, TINY].join('.')
16
16
  end
17
17
 
data/lib/amee/shell.rb CHANGED
@@ -13,56 +13,59 @@ module AMEE
13
13
  end
14
14
 
15
15
  def ls
16
- "listing contents of #{@@category}"
16
+ puts "Categories:"
17
+ @@category.children.each do |c|
18
+ puts " - #{c[:path]}"
19
+ end
20
+ puts "Items:"
21
+ @@category.items.each do |i|
22
+ puts " - #{i[:path]} (#{i[:label]})"
23
+ end
24
+ nil
17
25
  end
18
26
 
19
27
  def pwd
20
- @@category
28
+ @@category.full_path
21
29
  end
22
30
 
23
31
  def cd(path)
24
32
  if path == '..'
25
- path_components = @@category.split('/')
33
+ path_components = @@category.full_path.split('/')
26
34
  path = path_components.first(path_components.size - 1).join('/')
27
- elsif !path.match /^\/.*/
28
- path = @@category + '/' + path
35
+ elsif !path.match(/^\/.*/)
36
+ path = @@category.full_path + '/' + path
29
37
  end
30
- @@category = path
38
+ @@category = AMEE::Data::Category.get($connection, path)
39
+ @@category.full_path
31
40
  end
32
41
 
33
- def cat(object)
34
- "displaying contents of #{@@category}/#{object}"
42
+ def cat(name)
43
+ item = @@category.items.detect { |i| i[:path].match("^#{name}") }
44
+ fullpath = "#{@@category.full_path}/#{item[:path]}"
45
+ item = AMEE::Data::Item.get($connection, fullpath)
46
+ puts fullpath
47
+ puts "Label: #{item.label}"
48
+ puts "Values:"
49
+ item.values.each do |v|
50
+ puts " - #{v[:name]}: #{v[:value]}"
51
+ end
52
+ nil
35
53
  end
36
54
 
37
55
  end
38
56
  end
39
57
 
40
58
  require 'amee'
41
- require 'optparse'
42
59
  include AMEE::Shell
43
60
 
44
- # Command-line options - get username, password, and server
45
- options = {}
46
- OptionParser.new do |opts|
47
- opts.on("-u", "--username USERNAME", "AMEE username") do |u|
48
- options[:username] = u
49
- end
50
- opts.on("-p", "--password PASSWORD", "AMEE password") do |p|
51
- options[:password] = p
52
- end
53
- opts.on("-s", "--server SERVER", "AMEE server") do |s|
54
- options[:server] = s
55
- end
56
- end.parse!
57
-
58
- # Connect
59
- connection = AMEE::Connection.new(options[:server], options[:username], options[:password])
61
+ # Set up connection
62
+ $connection = AMEE::Connection.new(ENV['AMEE_SERVER'], ENV['AMEE_USERNAME'], ENV['AMEE_PASSWORD'])
60
63
 
61
- if connection.valid?
64
+ if $connection.valid?
62
65
  # Change to root of data api to get going
63
66
  cd '/data'
64
67
  # Display AMEE details
65
- amee_help
68
+ amee_help
66
69
  else
67
70
  puts "Can't connect to AMEE - please check details"
68
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Floppy-amee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
@@ -9,14 +9,14 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-11 00:00:00 -07:00
12
+ date: 2008-07-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description:
17
17
  email: james@floppy.org.uk
18
- executables: []
19
-
18
+ executables:
19
+ - ameesh
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files: []