rhcp_shell 0.0.7 → 0.0.9

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.
data/lib/rhcp_shell.rb DELETED
@@ -1,108 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "readline"
4
- require "logger"
5
- require "getoptlong"
6
-
7
- require 'rubygems'
8
-
9
- require 'rhcp'
10
-
11
- require 'base_shell'
12
- require 'rhcp_shell_backend'
13
-
14
- # TODO version number
15
- SHELL_VERSION = "0.1"
16
-
17
- class RhcpShell
18
-
19
- HELP_STRING = <<EOF
20
-
21
- RHCP Command Shell v #{SHELL_VERSION} (using RHCP library v #{RHCP::Version.to_s})
22
-
23
- Usage:
24
- rhcp_shell.rb [--hostname=<hostname>] [--username=<username> --password=<password>]
25
- [--help]
26
-
27
- Options:
28
- --hostname=<hostname>
29
- the URL to the RHCP server you want to connect against, e.g.
30
- http://server.local.network/rhcp
31
- If the specified hostname does not start with "http", it is automatically expanded to
32
- http://<hostname>:42000/rhcp
33
- You can optionally specify a port number to connect against like this:
34
- http://myserver:42000
35
- If you do not specify a hostname, the shell will try to connect against
36
- http://localhost:42000
37
-
38
- --username/--password
39
- the authentication data you want to use for connecting to the RHCP server
40
-
41
- --help
42
- displays this help screen.
43
-
44
- EOF
45
-
46
- def run
47
- opts = GetoptLong.new(
48
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
49
- [ '--username', '-u', GetoptLong::REQUIRED_ARGUMENT ],
50
- [ '--password', '-p', GetoptLong::REQUIRED_ARGUMENT ],
51
- [ '--hostname', GetoptLong::REQUIRED_ARGUMENT ]
52
- )
53
-
54
- options = Hash.new
55
- opts.each do |opt, arg|
56
- case opt
57
- when '--help'
58
- puts HELP_STRING
59
- Kernel.exit(1)
60
- else
61
- opt =~ /--(.+)/
62
- $logger.debug "setting #{arg} for #{$1}" unless $1 == "password"
63
- options[$1] = arg
64
- end
65
- end
66
-
67
- host = options["hostname"]
68
- if host == nil then
69
- host = "http://localhost:42000"
70
- else
71
- if host !~ /http:/ then
72
- host = "http://#{host}:42000/rhcp"
73
- end
74
- end
75
- $logger.debug "now connecting to #{host}"
76
-
77
- # TODO add interactive query for password!
78
-
79
- begin
80
- url = URI.parse(host)
81
- @http_broker = RHCP::Client::HttpBroker.new(url)
82
-
83
- backend = RHCPShellBackend.new(@http_broker)
84
- backend.banner = <<EOF
85
- Good morning, this is the generic RHCP Shell.
86
- Press <tab> for command completion or type "help" for a list of commands.
87
- If you want to exit this shell, please press Ctrl+C or type "exit".
88
-
89
- EOF
90
- $logger.debug "backend has been instantiated : #{backend}"
91
-
92
- shell = BaseShell.new(backend)
93
- shell.run
94
- rescue => ex
95
- puts "There occurred an HTTP error while connecting to the RHCP: #{ex}"
96
- puts "Please connect against another server or fix the connection problem."
97
- puts ex.backtrace.join("\n")
98
- end
99
- end
100
- end
101
-
102
-
103
- # TODO introduce something like the RAILS_ENVs
104
- $logger = Logger.new("rhcp_shell.log")
105
- RHCP::ModuleHelper.instance().logger = $logger
106
-
107
- shell = RhcpShell.new
108
- shell.run