marhan_cli 0.0.9 → 0.0.11

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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Changelog.md CHANGED
@@ -35,4 +35,13 @@
35
35
 
36
36
  ## v0.0.9
37
37
 
38
- * Name (configuration key) of device as parameter of unmount command. (command => crypt:unmount)
38
+ * Name (configuration key) of device as parameter of unmount command. (command => crypt:unmount)
39
+
40
+ ## v0.0.10
41
+
42
+ * Refactorings for cleaner code.
43
+
44
+ ## v0.0.11
45
+
46
+ * First RSpec tests and guard added for TDD development.
47
+ * VirtualBox command for start and stop virtual guest systems added. (command => vbox:[start|stop])
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/(.+)\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$})
4
+ end
5
+
data/README.md CHANGED
@@ -28,6 +28,11 @@ Configuration file `~/.marhan_cli.yml` is used for several commands
28
28
  mount_folder: /Volumes
29
29
  encrypted_devices:
30
30
  enc1: /dev/rdisk1s2
31
+ hdd: /dev/rdisk2s2
32
+ vbox:
33
+ guests:
34
+ linux: Linux
35
+ windows: Windows XP
31
36
 
32
37
  ## Contributing
33
38
 
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require 'marhan_cli/helper/constraint'
3
+
4
+ module MarhanCli
5
+ class VirtualBoxApp
6
+
7
+ attr_reader :guests
8
+
9
+ def initialize(guests)
10
+ @guests = guests
11
+ end
12
+
13
+ def start_guest(guest_config_name)
14
+ "VBoxManage startvm '#{vbox_name(guest_config_name)}'"
15
+ end
16
+
17
+ def stop_guest(guest_config_name)
18
+ "VBoxManage controlvm '#{vbox_name(guest_config_name)}' poweroff"
19
+ end
20
+
21
+ def vbox_name(guest_config_name)
22
+ Constraint.not_nil_or_empty! guest_config_name, "Guest config name have to be set!"
23
+ vbox_name = @guests[guest_config_name]
24
+ Constraint.not_nil_or_empty! vbox_name, "No guest with key '#{guest_config_name}' found in configuration"
25
+ vbox_name
26
+ end
27
+ end
28
+ end
@@ -10,6 +10,19 @@ module MarhanCli
10
10
 
11
11
  CONFIG_FILE = ".marhan_cli.yml"
12
12
 
13
+ def execute(proc)
14
+ begin
15
+ say ""
16
+ say "Starting command...", :green
17
+ say ""
18
+ proc.call
19
+ say ""
20
+ say "End of command", :green
21
+ rescue Exception => e
22
+ exit_with_error(e)
23
+ end
24
+ end
25
+
13
26
  def exit_with_error(message)
14
27
  say message, :red
15
28
  exit(1)
@@ -20,7 +33,6 @@ module MarhanCli
20
33
  unless File.exists?(config_file_path)
21
34
  raise "Stop processing! Command needs the configuration file '#{CONFIG_FILE}' in you're home directory."
22
35
  end
23
- #say "I will use the '#{CONFIG_FILE}' configuration file in you're home directory.", :cyan
24
36
  config = Ambience.create(config_file_path)
25
37
  config.to_mash
26
38
  end
@@ -15,15 +15,7 @@ module MarhanCli
15
15
  :desc => "Name of device in configuration file."
16
16
 
17
17
  def mount
18
- begin
19
- config = load_crypt_config
20
- true_crypt = TrueCryptApp.new(config.mount_folder)
21
- device = get_or_ask(:device)
22
- run true_crypt.mount_command(config.encrypted_devices[device], device)
23
- say "finished", :green
24
- rescue Exception => e
25
- exit_with_error(e)
26
- end
18
+ execute mount_proc
27
19
  end
28
20
 
29
21
  desc "crypt:umount", "Unmounts encrypted disk with TrueCrypt"
@@ -34,31 +26,42 @@ module MarhanCli
34
26
  :desc => "Name of device in configuration file."
35
27
 
36
28
  def umount
37
- begin
29
+ execute unmount_proc
30
+ end
31
+
32
+ desc "crypt:umount_all", "Unmounts all encrypted disk with TrueCrypt"
33
+
34
+ def umount_all
35
+ execute unmount_all_proc
36
+ end
37
+
38
+ private
39
+
40
+ def mount_proc
41
+ Proc.new do
38
42
  config = load_crypt_config
39
43
  true_crypt = TrueCryptApp.new(config.mount_folder)
40
44
  device = get_or_ask(:device)
41
- run true_crypt.unmount_command(device)
42
- say "finished", :green
43
- rescue Exception => e
44
- exit_with_error(e)
45
+ run true_crypt.mount_command(config.encrypted_devices[device], device)
45
46
  end
46
47
  end
47
48
 
48
- desc "crypt:umount_all", "Unmounts all encrypted disk with TrueCrypt"
49
+ def unmount_proc
50
+ Proc.new do
51
+ config = load_crypt_config
52
+ true_crypt = TrueCryptApp.new(config.mount_folder)
53
+ device = get_or_ask(:device)
54
+ run true_crypt.unmount_command(device)
55
+ end
56
+ end
49
57
 
50
- def umount_all
51
- begin
58
+ def unmount_all_proc
59
+ Proc.new do
52
60
  true_crypt = TrueCryptApp.new
53
61
  run true_crypt.unmount_all_command
54
- say "finished", :green
55
- rescue Exception => e
56
- exit_with_error(e)
57
62
  end
58
63
  end
59
64
 
60
- protected
61
-
62
65
  def load_crypt_config
63
66
  load_config.crypt
64
67
  end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ require 'marhan_cli/command'
3
+ require 'marhan_cli/app/virtual_box_app'
4
+
5
+ module MarhanCli
6
+ class VBox < MarhanCli::Command
7
+
8
+ namespace :vbox
9
+
10
+ desc "vbox:start", "Starts VirtualBox guest system"
11
+
12
+ method_option :guest,
13
+ :type => :string,
14
+ :aliases => "-g",
15
+ :desc => "Name of the guest system in configuration file."
16
+
17
+ def start
18
+ execute start_guest
19
+ end
20
+
21
+ desc "vbox:stop", "Stops VirtualBox guest system"
22
+
23
+ method_option :guest,
24
+ :type => :string,
25
+ :aliases => "-g",
26
+ :desc => "Name of the guest system in configuration file."
27
+
28
+ def stop
29
+ execute stop_guest
30
+ end
31
+
32
+ private
33
+
34
+ def start_guest
35
+ Proc.new do
36
+ config = load_vbox_config
37
+ virtual_box = VirtualBoxApp.new(config.guests)
38
+ guest_to_start = get_or_ask(:guest)
39
+ run virtual_box.start_guest(guest_to_start)
40
+ end
41
+ end
42
+
43
+ def stop_guest
44
+ Proc.new do
45
+ config = load_vbox_config
46
+ virtual_box = VirtualBoxApp.new(config.guests)
47
+ guest_to_start = get_or_ask(:guest)
48
+ run virtual_box.stop_guest(guest_to_start)
49
+ end
50
+ end
51
+
52
+ def load_vbox_config
53
+ load_config.vbox
54
+ end
55
+
56
+ end
57
+ end
@@ -7,13 +7,21 @@ module MarhanCli
7
7
 
8
8
  namespace :web
9
9
 
10
- desc "web:my-ip", "Gives out the external IP from the world wide web"
10
+ desc "web:myip", "Gives out the external IP from the world wide web"
11
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)
12
+ def myip
13
+ execute my_ip_proc()
14
+ end
15
+
16
+ private
17
+
18
+ def my_ip_proc
19
+ Proc.new do
20
+ uri = URI('http://checkip.dyndns.org')
21
+ response = Net::HTTP.get(uri)
22
+ ip_address = /[0-9\.]+/.match(response)
23
+ say("Your public IP is: #{ip_address}", :cyan)
24
+ end
17
25
  end
18
26
 
19
27
  end
@@ -1,9 +1,15 @@
1
1
  module MarhanCli
2
2
  class Constraint
3
3
 
4
- def self.notNil!(argument, argument_name)
4
+ def self.not_nil!(argument, argument_name)
5
5
  raise ArgumentError, "Given argument '#{argument_name}' must not be nil" if argument.nil?
6
6
  end
7
7
 
8
+ def self.not_nil_or_empty!(argument, message)
9
+ if argument.nil? or argument.empty?
10
+ raise ArgumentError, message
11
+ end
12
+ end
13
+
8
14
  end
9
15
  end
@@ -5,16 +5,16 @@ module MarhanCli
5
5
  class RemoteMachine
6
6
 
7
7
  def initialize(host, port)
8
- Constraint.notNil!(host, "host")
9
- Constraint.notNil!(port, "port")
8
+ Constraint.not_nil!(host, "host")
9
+ Constraint.not_nil!(port, "port")
10
10
  @host = host
11
11
  @port = port
12
12
  end
13
13
 
14
14
  def add_id_to_authorized_keys(user, password, id_file)
15
- Constraint.notNil!(user, "user")
16
- Constraint.notNil!(password, "password")
17
- Constraint.notNil!(id_file, "id_file")
15
+ Constraint.not_nil!(user, "user")
16
+ Constraint.not_nil!(password, "password")
17
+ Constraint.not_nil!(id_file, "id_file")
18
18
 
19
19
  id_pub_content = File.read File.expand_path(id_file)
20
20
  id_pub_content = id_pub_content.chomp
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module MarhanCli
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.11"
4
4
  end
data/marhan_cli.gemspec CHANGED
@@ -20,4 +20,10 @@ Gem::Specification.new do |gem|
20
20
  gem.add_runtime_dependency('thor')
21
21
  gem.add_runtime_dependency('net-ssh', '~> 2.6.1')
22
22
  gem.add_runtime_dependency('ambience', '~> 2.0.0')
23
+
24
+ gem.add_development_dependency('rspec', '~> 2.12.0')
25
+ gem.add_development_dependency('guard', '~> 1.5.4')
26
+ gem.add_development_dependency('guard-rspec', '~> 2.3.1')
27
+ gem.add_development_dependency('rb-fsevent', '~> 0.9.1')
28
+
23
29
  end
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'marhan_cli/app/virtual_box_app'
4
+
5
+ describe "VirtualBoxApp" do
6
+
7
+ let(:config_param) { Hashie::Mash.new(:linux => 'Ubuntu Linux') }
8
+
9
+ context ".new" do
10
+ describe "with empty hash as argument" do
11
+ let(:subject) { MarhanCli::VirtualBoxApp.new({}) }
12
+ it "creates a new objects" do
13
+ subject.should be_a(MarhanCli::VirtualBoxApp)
14
+ end
15
+ end
16
+
17
+ describe "with config hash as argument" do
18
+ let(:subject) { MarhanCli::VirtualBoxApp.new(config_param) }
19
+
20
+ it "has set config hash" do
21
+ subject.guests.should eq(config_param)
22
+ end
23
+ end
24
+ end
25
+
26
+ context ".start_guest" do
27
+ let(:subject) { MarhanCli::VirtualBoxApp.new(config_param) }
28
+
29
+ describe "with configured guest as argument" do
30
+ it "returns correct command" do
31
+ subject.start_guest('linux').should eq("VBoxManage startvm 'Ubuntu Linux'")
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ context ".vbox_name" do
38
+ let(:subject) { MarhanCli::VirtualBoxApp.new(config_param) }
39
+
40
+ describe "with configured guest as argument" do
41
+ it "returns correct command" do
42
+ subject.vbox_name('linux').should eq('Ubuntu Linux')
43
+ end
44
+ end
45
+
46
+ describe "with not configured guest as argument" do
47
+ it "raise error" do
48
+ expect {
49
+ subject.vbox_name('minix')
50
+ }.to raise_error(
51
+ error=ArgumentError,
52
+ message="No guest with key 'minix' found in configuration")
53
+ end
54
+ end
55
+
56
+ describe "with empty guest as argument" do
57
+ it "raise error" do
58
+ expect {
59
+ subject.vbox_name('')
60
+ }.to raise_error(
61
+ error=ArgumentError,
62
+ message="Guest config name have to be set!")
63
+ end
64
+ end
65
+ end
66
+
67
+ context ".stop_guest" do
68
+
69
+ let(:subject) { MarhanCli::VirtualBoxApp.new(config_param) }
70
+
71
+ describe "with configured guest as argument" do
72
+ it "returns correct command" do
73
+ subject.stop_guest('linux').should eq("VBoxManage controlvm 'Ubuntu Linux' poweroff")
74
+ end
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'marhan_cli/helper/constraint'
4
+
5
+ describe "Constraint" do
6
+
7
+ context ".not_nil!" do
8
+ describe "with nil as argument" do
9
+ it "throws exception" do
10
+ expect { MarhanCli::Constraint.not_nil!(nil, "") }.to raise_error
11
+ end
12
+ end
13
+
14
+ describe "with valid string as argument" do
15
+ it "throws exception" do
16
+ expect { MarhanCli::Constraint.not_nil!("any_string", "any_string") }.to_not raise_error
17
+ end
18
+ end
19
+ end
20
+
21
+ context ".not_nil_or_empty!" do
22
+ describe "with nil as argument" do
23
+ it "throws exception" do
24
+ expect { MarhanCli::Constraint.not_nil_or_empty!(nil, "") }.to raise_error
25
+ end
26
+ end
27
+ describe "with empty string as argument" do
28
+ it "throws exception" do
29
+ expect { MarhanCli::Constraint.not_nil_or_empty!("", "") }.to raise_error
30
+ end
31
+ end
32
+
33
+ describe "with valid string as argument" do
34
+ it "throws no exception" do
35
+ expect { MarhanCli::Constraint.not_nil!("any_string", "any_string") }.to_not raise_error
36
+ end
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,18 @@
1
+ require 'hashie'
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # Require this file using `require "spec_helper"` to ensure that it is only
5
+ # loaded once.
6
+ #
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ 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.9
4
+ version: 0.0.11
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-03 00:00:00.000000000 Z
12
+ date: 2012-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -59,6 +59,70 @@ dependencies:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.5.4
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.5.4
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 2.3.1
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 2.3.1
110
+ - !ruby/object:Gem::Dependency
111
+ name: rb-fsevent
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.9.1
62
126
  description:
63
127
  email: me@markushanses.de
64
128
  executables:
@@ -67,24 +131,31 @@ extensions: []
67
131
  extra_rdoc_files: []
68
132
  files:
69
133
  - .gitignore
134
+ - .rspec
70
135
  - .rvmrc
71
136
  - Changelog.md
72
137
  - Gemfile
138
+ - Guardfile
73
139
  - LICENSE.txt
74
140
  - README.md
75
141
  - Rakefile
76
142
  - bin/mcli
77
143
  - lib/marhan_cli.rb
78
144
  - lib/marhan_cli/app/true_crypt_app.rb
145
+ - lib/marhan_cli/app/virtual_box_app.rb
79
146
  - lib/marhan_cli/command.rb
80
147
  - lib/marhan_cli/commands/network.rb
81
148
  - lib/marhan_cli/commands/true_crypt.rb
149
+ - lib/marhan_cli/commands/vbox.rb
82
150
  - lib/marhan_cli/commands/web.rb
83
151
  - lib/marhan_cli/helper/constraint.rb
84
152
  - lib/marhan_cli/network/errors.rb
85
153
  - lib/marhan_cli/network/remote_machine.rb
86
154
  - lib/marhan_cli/version.rb
87
155
  - marhan_cli.gemspec
156
+ - spec/marhan_cli/app/virtual_box_app_spec.rb
157
+ - spec/marhan_cli/helper/constraint_spec.rb
158
+ - spec/spec_helper.rb
88
159
  homepage: https://github.com/marhan/marhan_cli
89
160
  licenses: []
90
161
  post_install_message:
@@ -109,4 +180,7 @@ rubygems_version: 1.8.24
109
180
  signing_key:
110
181
  specification_version: 3
111
182
  summary: Helper routines for my computers
112
- test_files: []
183
+ test_files:
184
+ - spec/marhan_cli/app/virtual_box_app_spec.rb
185
+ - spec/marhan_cli/helper/constraint_spec.rb
186
+ - spec/spec_helper.rb