marhan_cli 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -1
- data/Changelog.md +14 -2
- data/README.md +1 -1
- data/bin/mcli +1 -1
- data/lib/marhan_cli.rb +22 -2
- data/lib/marhan_cli/command.rb +9 -0
- data/lib/marhan_cli/commands/network.rb +57 -0
- data/lib/marhan_cli/commands/web.rb +20 -0
- data/lib/marhan_cli/{cli/helper → helper}/constraint.rb +0 -0
- data/lib/marhan_cli/{cli/server → server}/errors.rb +0 -0
- data/lib/marhan_cli/{cli/server → server}/remote_machine.rb +1 -1
- data/lib/marhan_cli/version.rb +2 -1
- metadata +8 -7
- data/lib/marhan_cli/cli.rb +0 -10
- data/lib/marhan_cli/cli/commands/server.rb +0 -33
data/.gitignore
CHANGED
data/Changelog.md
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
## v0.0.1
|
2
2
|
|
3
3
|
* Initial release
|
4
|
-
*
|
4
|
+
* Copy the ssh id file into the ~/.ssh/authorized_keys of a remote machine. (command => add-ssh-key)
|
5
5
|
|
6
6
|
## v0.0.2
|
7
7
|
|
8
|
-
* Output
|
8
|
+
* Output improved. (command => add-ssh-key)
|
9
|
+
|
10
|
+
## v0.0.4
|
11
|
+
|
12
|
+
* Retrieves the external ip address from the world wide web. (command => my-net-ip)
|
13
|
+
|
14
|
+
## v0.0.5
|
15
|
+
|
16
|
+
* Add MarhanCli command list as default task list to Thor.
|
17
|
+
* Introduce namespaces to commands. Building Groups with the namespaces 'web' and 'net'.
|
18
|
+
* Command names renamed:
|
19
|
+
**my-net-ip** renamed to **web:my-ip**
|
20
|
+
**add-ssh-key** renamed to **net:add-ssh-key**
|
9
21
|
|
data/README.md
CHANGED
data/bin/mcli
CHANGED
data/lib/marhan_cli.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/runner'
|
2
3
|
|
3
4
|
module MarhanCli
|
4
|
-
|
5
|
+
|
6
|
+
def self.start
|
7
|
+
require_commands
|
8
|
+
run_thor
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.require_commands
|
14
|
+
path_to_commands = File.expand_path '../marhan_cli/commands/*.rb', __FILE__
|
15
|
+
Dir[path_to_commands].each do |f|
|
16
|
+
require f
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.run_thor
|
21
|
+
Thor.default_task 'list'
|
22
|
+
Thor::Runner.start
|
23
|
+
end
|
24
|
+
|
5
25
|
end
|
6
26
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'marhan_cli/server/remote_machine'
|
3
|
+
require 'marhan_cli/command'
|
4
|
+
|
5
|
+
module MarhanCli
|
6
|
+
class Network < MarhanCli::Command
|
7
|
+
|
8
|
+
namespace :net
|
9
|
+
|
10
|
+
desc "net:add-ssh-key", "Copies public ssh id into authorized_keys"
|
11
|
+
|
12
|
+
method_option :user,
|
13
|
+
:type => :string,
|
14
|
+
:aliases => "-u",
|
15
|
+
:desc => "Name of user on remote machine"
|
16
|
+
|
17
|
+
method_option :host,
|
18
|
+
:type => :string,
|
19
|
+
:aliases => "-h",
|
20
|
+
:desc => "Name of remote machine"
|
21
|
+
|
22
|
+
method_option :port,
|
23
|
+
:type => :numeric,
|
24
|
+
:aliases => "-p",
|
25
|
+
:default => 22,
|
26
|
+
:desc => "Port of remote machine"
|
27
|
+
|
28
|
+
method_option :file,
|
29
|
+
:type => :string,
|
30
|
+
:aliases => "-f",
|
31
|
+
:default => "~/.ssh/id_rsa.pub",
|
32
|
+
:desc => "Path of id file"
|
33
|
+
|
34
|
+
def add_ssh_key
|
35
|
+
host = options[:host] || get_option(:host)
|
36
|
+
user = options[:user] || get_option(:user)
|
37
|
+
password = options[:password] || get_option(:password)
|
38
|
+
id_file = options[:file]
|
39
|
+
port = options[:port]
|
40
|
+
|
41
|
+
remote_machine = RemoteMachine.new(host, port)
|
42
|
+
remote_machine.add_id_to_authorized_keys(user, password, id_file)
|
43
|
+
say "successfully copied #{id_file} to #{host}", :green
|
44
|
+
rescue Exception => e
|
45
|
+
say "copying of id file to remote machine failed: #{e}", :red
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def get_option(option)
|
52
|
+
value = ask("Please enter #{option}:")
|
53
|
+
raise Thor::Error, "You must enter a value for that field." if value.empty?
|
54
|
+
value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'net/http'
|
3
|
+
require 'marhan_cli/command'
|
4
|
+
|
5
|
+
module MarhanCli
|
6
|
+
class Web < MarhanCli::Command
|
7
|
+
|
8
|
+
namespace :web
|
9
|
+
|
10
|
+
desc "web:my-ip", "Gives out the external IP from the world wide web"
|
11
|
+
|
12
|
+
def my_ip
|
13
|
+
uri = URI('http://checkip.dyndns.org')
|
14
|
+
response = Net::HTTP.get(uri)
|
15
|
+
ip_address = /[0-9\.]+/.match(response)
|
16
|
+
say("Your public IP is: #{ip_address}", :blue)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
File without changes
|
data/lib/marhan_cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marhan_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -59,11 +59,12 @@ files:
|
|
59
59
|
- Rakefile
|
60
60
|
- bin/mcli
|
61
61
|
- lib/marhan_cli.rb
|
62
|
-
- lib/marhan_cli/
|
63
|
-
- lib/marhan_cli/
|
64
|
-
- lib/marhan_cli/
|
65
|
-
- lib/marhan_cli/
|
66
|
-
- lib/marhan_cli/
|
62
|
+
- lib/marhan_cli/command.rb
|
63
|
+
- lib/marhan_cli/commands/network.rb
|
64
|
+
- lib/marhan_cli/commands/web.rb
|
65
|
+
- lib/marhan_cli/helper/constraint.rb
|
66
|
+
- lib/marhan_cli/server/errors.rb
|
67
|
+
- lib/marhan_cli/server/remote_machine.rb
|
67
68
|
- lib/marhan_cli/version.rb
|
68
69
|
- marhan_cli.gemspec
|
69
70
|
homepage: https://github.com/marhan/marhan_cli
|
data/lib/marhan_cli/cli.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module MarhanCli
|
2
|
-
class Cli
|
3
|
-
include Thor::Actions
|
4
|
-
|
5
|
-
desc "add-ssh-key", "Copies public ssh id into authorized_keys"
|
6
|
-
method_option :user, :type => :string, :aliases => "-u", :desc => "Name of user on remote machine"
|
7
|
-
method_option :host, :type => :string, :aliases => "-h", :desc => "Name of remote machine"
|
8
|
-
method_option :port, :type => :numeric, :aliases => "-p", :default => 22, :desc => "Port of remote machine"
|
9
|
-
method_option :file, :type => :string, :aliases => "-f", :default => "~/.ssh/id_rsa.pub", :desc => "Path of id file"
|
10
|
-
|
11
|
-
def add_ssh_key
|
12
|
-
host = options[:host] || get_option(:host)
|
13
|
-
user = options[:user] || get_option(:user)
|
14
|
-
password = options[:password] || get_option(:password)
|
15
|
-
id_file = options[:file]
|
16
|
-
port = options[:port]
|
17
|
-
|
18
|
-
remote_machine = RemoteMachine.new(host, port)
|
19
|
-
remote_machine.add_id_to_authorized_keys(user, password, id_file)
|
20
|
-
say "successfully copied #{id_file} to #{host}", :green
|
21
|
-
rescue Exception => e
|
22
|
-
say "copying of id file to remote machine failed: #{e}", :red
|
23
|
-
end
|
24
|
-
|
25
|
-
protected
|
26
|
-
|
27
|
-
def get_option(option)
|
28
|
-
value = ask("Please enter #{option}:")
|
29
|
-
raise Thor::Error, "You must enter a value for that field." if value.empty?
|
30
|
-
value
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|