marhan_cli 0.0.2 → 0.0.5

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/.gitignore CHANGED
@@ -17,4 +17,8 @@ test/version_tmp
17
17
  tmp
18
18
 
19
19
  # Ruby Mine
20
- .idea
20
+ .idea
21
+
22
+ # vim
23
+ *.swp
24
+
@@ -1,9 +1,21 @@
1
1
  ## v0.0.1
2
2
 
3
3
  * Initial release
4
- * Copying of ssh id file into the ~/.ssh/authorized_keys of a remote machine. (command: add-ssh-key)
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 improvement. (command: add-ssh-key)
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
@@ -1,6 +1,6 @@
1
1
  # MarhanCli
2
2
 
3
- TODO: Write a gem description
3
+ This gem is a toolset my my own needs.
4
4
 
5
5
  ## Installation
6
6
 
data/bin/mcli CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "marhan_cli"
3
- MarhanCli::Cli.start
3
+ MarhanCli.start
@@ -1,6 +1,26 @@
1
- require "marhan_cli/cli"
1
+ require 'thor'
2
+ require 'thor/runner'
2
3
 
3
4
  module MarhanCli
4
- #noop
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,9 @@
1
+ # encoding: utf-8
2
+ require "thor"
3
+
4
+ module MarhanCli
5
+ class Command < Thor
6
+ include Thor::Actions
7
+
8
+ end
9
+ end
@@ -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
@@ -1,5 +1,5 @@
1
1
  require 'net/ssh'
2
- require 'marhan_cli/cli/helper/constraint'
2
+ require 'marhan_cli/helper/constraint'
3
3
 
4
4
  module MarhanCli
5
5
  class RemoteMachine
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module MarhanCli
2
- VERSION = "0.0.2"
3
+ VERSION = "0.0.5"
3
4
  end
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.2
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-10-25 00:00:00.000000000 Z
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/cli.rb
63
- - lib/marhan_cli/cli/commands/server.rb
64
- - lib/marhan_cli/cli/helper/constraint.rb
65
- - lib/marhan_cli/cli/server/errors.rb
66
- - lib/marhan_cli/cli/server/remote_machine.rb
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
@@ -1,10 +0,0 @@
1
- require "thor"
2
- require 'marhan_cli/cli/server/remote_machine'
3
-
4
- module MarhanCli
5
- class Cli < Thor
6
-
7
- end
8
- end
9
-
10
- require "marhan_cli/cli/commands/server"
@@ -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