russh 0.0.4 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6b58687995f56f61085d7677ccd954d9154f022
4
- data.tar.gz: 1bb4112725d4a2b02a40ca1f8e135746044bf9f7
3
+ metadata.gz: 1914bfc930ce7a0fe5d96e79309e8694d49287cc
4
+ data.tar.gz: de673be7381035aa26230359be3654a30db6f0bc
5
5
  SHA512:
6
- metadata.gz: c535c81250d14a372582302534485dbe78e667b2f4f235f223317067f6b1b923fd0d257de71be27993785cb97d38332d9b7b47e253bd4f6d20879b53b37ba4d8
7
- data.tar.gz: fd391a2638de2c3ec1503f0ff6ef493a7bd61f36753853d2bbab4185006c005afa5f031ea9a34850345db2726c83d269814a30bff2d584bc36962e9ddd77d9c5
6
+ metadata.gz: 0b476daad69ad412a0578dcb2bfa9458a40ed6bd0271c1f8dfa8d0f4de9e1b0382826beb8fd9a48ba49a646fd6891cf629088897e1c0935aef82026e240995ea
7
+ data.tar.gz: f8dea1d5ec7c589876608ee245fccf4cd7a81acf1a86be5bceb65a874b151d22c5d9a9c931136baa9caf2928d83635ec42d0f87d972aab4fa5586fc0e97f7e01
data/README.md CHANGED
@@ -1,24 +1,21 @@
1
1
  # Russh
2
2
 
3
- **Russh =** Ruby + SSH . SSH Config Manager for Ruby.
3
+ **Russh =** Ruby + SSH . SSH Config Manager for Ruby. It helps you manage your SSH configuration.
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'russh'
10
-
11
- And then execute:
5
+ You can create, delete and update your existing configuration.
12
6
 
13
- $ bundle
7
+ Currently under heavy development.
14
8
 
15
- Or install it yourself as:
9
+ ## Installation
16
10
 
17
11
  $ gem install russh
18
12
 
19
13
  ## Usage
20
14
 
21
- TODO: Write usage instructions here
15
+ ### Create a new configuration
16
+
17
+ russh create
18
+
22
19
 
23
20
  ## Contributing
24
21
 
@@ -6,18 +6,40 @@ module Russh
6
6
 
7
7
  def initialize
8
8
  @path = Dir.home + '/.ssh/config'
9
- @is_readable = File.readable? @path
10
- @is_writable = File.writable? @path
9
+ @is_existing = is_existing?
10
+ @is_readable = is_readable?
11
+ @is_writable = is_writable?
11
12
  end
12
13
 
14
+ # Checks if the config file is existing. If not it creates a new one.
15
+ def is_existing?
16
+ if File.exist? @path
17
+ @is_existing = true
18
+ else
19
+ puts "You don't have an existing ssh config file. Creating a new one for you."
20
+ File.new(@path, 'w')
21
+ end
22
+ end
23
+
24
+ # Checks if the config file is readable.
13
25
  def is_readable?
14
- @is_readable
26
+ begin
27
+ @is_readable = File.readable? @path
28
+ rescue => e
29
+ puts "Couldn't be able to read your ssh config: Error #{e}"
30
+ end
15
31
  end
16
32
 
33
+ # Checks if the config file is writable.
17
34
  def is_writable?
18
- @is_writable
35
+ begin
36
+ @is_writable = File.writable? @path
37
+ rescue => e
38
+ puts "Couldn't be able to write your ssh config: Error #{e}"
39
+ end
19
40
  end
20
41
 
42
+ # Backups the config file to config.bk
21
43
  def backup
22
44
  if is_readable?
23
45
  FileUtils.cp @path, "#{@path}.bk"
@@ -30,18 +52,28 @@ module Russh
30
52
  end
31
53
  end
32
54
 
33
- def create
34
- @host = ask 'Host'
35
- @host_name = ask 'HostName'
36
- @user = ask 'User'
55
+ def create(host, host_name, user)
56
+ # Ask the user for input
57
+ @host = host
58
+ @host_name = host_name
59
+ @user = user
60
+ # Check for read and write access
37
61
  if is_readable? && is_writable?
38
62
  backup
39
- open(@path, 'a') do |f|
40
- f.puts "Host #{@host}"
41
- f.puts " HostName #{@host_name}"
42
- f.puts " User #{@user}"
63
+ open(@path, 'a+') do |f|
64
+ # If the file is new don't add a newline.
65
+ f.puts if f.readlines.size > 0
66
+ # Format each entry
67
+ f.puts format_entry
43
68
  end
44
69
  end
45
70
  end
71
+
72
+ protected
73
+
74
+ # Formats each entry
75
+ def format_entry
76
+ "Host #{@host}\n\tHostName #{@host_name}\n\tUser #{@user}"
77
+ end
46
78
  end
47
79
  end
data/lib/russh/cli.rb CHANGED
@@ -7,17 +7,29 @@ module Russh
7
7
  include Commander::Methods
8
8
 
9
9
  def run
10
- program :name, 'Rrush'
10
+ program :name, 'Russh'
11
11
  program :version, VERSION
12
12
  program :description, 'SSH Config Manager For Ruby'
13
13
 
14
14
  command :create do |c|
15
- c.syntax = 'russh create'
15
+ c.syntax = 'russh create [options]'
16
16
  c.description = 'Creates a new host'
17
+ c.option '--alias STRING', String, 'Host Alias'
18
+ c.option '--host STRING', String, 'Host Address'
19
+ c.option '--user STRING', String, 'Username'
17
20
  c.action do |args, options|
18
- Accessor.new.create
21
+ Accessor.new.create options.alias, options.host, options.user
19
22
  end
20
23
  end
24
+
25
+ command :backup do |c|
26
+ c.syntax = 'russh backup'
27
+ c.description = 'Backups your ssh config'
28
+ c.action do |args, options|
29
+ Accessor.new.backup
30
+ end
31
+ end
32
+
21
33
  run!
22
34
  end
23
35
  end
data/lib/russh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Russh
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -14,6 +14,7 @@ describe Russh::Accessor do
14
14
  context 'backup' do
15
15
  it 'should copy the original config' do
16
16
  original_file = subject.read
17
+ subject.backup
17
18
  File.read(subject.path + '.bk').should == original_file
18
19
  end
19
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: russh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serdar Dogruyol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-08 00:00:00.000000000 Z
11
+ date: 2014-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler