thorium 0.3.3 → 0.3.4

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: d0be3adba8cd2cbb26b1afeea7fd9c2ee1d0232c
4
- data.tar.gz: c5f5b2c231ff20c98cb109722bee1eb39e483162
3
+ metadata.gz: 1915fb23dbce02dc16d56d322810e1424eedcdae
4
+ data.tar.gz: 187107add74947748aa10894cc641c15e7472f01
5
5
  SHA512:
6
- metadata.gz: b266ff24f8d12859f3090733b31df86627778c53fddd78931cbac3208ad29487dedaf1070b71abb40f0bd11da7b5623d6b108afc826d5982291d4eee4bdf9a5a
7
- data.tar.gz: 136274242cfbe0e4778c47e16721b1f2a98abb90656b1481c1b231e013b5eb8030313282447908eb9904bb18f3b1f2098f91808d016423e27e4dfe2b46292308
6
+ metadata.gz: 8ee9a2f61e2599e10ee02b050d33323ceba8151cfcc18ad459fb72a1a9c4ca7df530cf1e7c8deb0585778d9df31ff1691c290b434a4c1fcc71a2331bc181ee6c
7
+ data.tar.gz: 8125cc0c92d8c352da5e773411d85fc46c5e444b6cb81c07f0e5cbb6c93f484a6d782d51efc7ff05177aab9f5945196389858223a8974b1e52c7bd8b029bd8f5
data/bin/thorium CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'thorium'
4
3
 
5
- ThoriumCLI::Thorium.start(ARGV)
4
+ ThoriumCLI::Thorium.start(ARGV)
data/lib/thorium.rb CHANGED
@@ -1 +1 @@
1
- require_relative 'thorium/base'
1
+ require_relative 'thorium/base'
data/lib/thorium/base.rb CHANGED
@@ -8,43 +8,63 @@ require_relative 'tasks/apache'
8
8
  require_relative 'tasks/git'
9
9
 
10
10
  module ThoriumCLI
11
+ # Top level tasks for thorium
12
+ # Includes routines that do not require packaging of subcomands
11
13
  class Thorium < Thor
12
14
  package_name 'Thorium'
15
+ SKIP = ''
16
+ ALIAS = 'th'
17
+ OS = ENV['_system_type']
13
18
 
14
19
  include Thor::Actions
15
20
  include ApacheCLI
16
21
  include GitCLI
17
22
 
18
- class_option :verbose, :type => :boolean, :default => false
19
- @@os = ENV['_system_type']
20
- @@skip = ""
23
+ class_option :verbose, type: :boolean, default: false, aliases: :v
21
24
 
22
- desc "pubkeys", "Simple public keys manipulation tool"
25
+ desc 'pubkeys', 'Simple public keys manipulation'
23
26
  def pubkeys
24
- public_keys = Dir.glob(File.expand_path("~/.ssh") + "/*.pub")
27
+ public_keys = Dir.glob(File.expand_path('~/.ssh') + '/*.pub')
25
28
  if public_keys.any?
26
- puts "\nPublic keys found:"
27
- puts "------------------"
28
- public_keys.each_with_index do |f, i|
29
- say "[#{i+1}] #{f}", :blue
30
- run "cat #{f}", verbose: false
31
- end
32
- ask_options = {:limited_to => ("1".."#{public_keys.size}").to_a, skip: @@skip}
33
- index = ask("Which key do you want in your clipboard?", :green, ask_options)
34
- run "pbcopy < #{public_keys[index.to_i-1]}" unless index == ask_options[:skip]
29
+ puts '', 'Public keys found:'
30
+ puts '------------------'
31
+ print_keys public_keys
32
+ ask_options = { limited_to: ('1'..public_keys.size.to_s).to_a, skip: SKIP }
33
+ index = ask('Which key do you want in your clipboard?', :green, ask_options)
34
+ copy_to_clipboard public_keys[index.to_i - 1] if index != ask_options[:skip]
35
35
  else
36
- say "No public keys have been found.", :red
37
- generate_new = yes?("Do you want to generate a new one?", :green)
38
- run "ssh-keygen" if generate_new
36
+ say 'No public keys have been found.', :red
37
+ generate_new = yes?('Do you want to generate a new one?', :green)
38
+ run 'ssh-keygen' if generate_new
39
39
  end
40
40
  end
41
41
 
42
42
  # Apache subcommand
43
- desc "apache [SUBCOMMAND] [ARGS]", "Control Apache with ease!"
44
- subcommand "apache", Apache
43
+ desc 'apache [SUBCOMMAND] [ARGS]', 'Control Apache with ease!'
44
+ subcommand 'apache', Apache
45
45
 
46
46
  # Git subcommand
47
- desc "git [SUBCOMMAND] [ARGS]", "Git wrapper"
48
- subcommand "git", Git
47
+ desc 'git [SUBCOMMAND] [ARGS]', 'Git wrapper'
48
+ subcommand 'git', Git
49
+
50
+ no_commands do
51
+
52
+ private
53
+ # Prints public keys with indexes
54
+ def print_keys(public_keys)
55
+ public_keys.each_with_index do |f, i|
56
+ say "[#{i + 1}] #{f}", :blue
57
+ run "cat #{f}", verbose: false
58
+ end
59
+ end
60
+
61
+ def copy_to_clipboard(content)
62
+ if run 'which pbcopy > /dev/null', verbose: false
63
+ run "pbcopy < #{content}"
64
+ else
65
+ say 'pbcopy is not installed, cannot copy to clipboard', :red
66
+ end
67
+ end
68
+ end
49
69
  end
50
- end
70
+ end
@@ -1,25 +1,36 @@
1
- require "thor"
1
+ require 'thor'
2
2
 
3
3
  class Thor
4
4
  module Shell
5
+ # Top level commit
5
6
  class Basic
6
-
7
7
  def ask_filtered(statement, color, options)
8
8
  answer_set = options[:limited_to]
9
- correct_answer = nil
10
- if options.has_key? :skip
11
- statement += options[:skip].strip.empty? ? " (Enter to skip)" : " (#{options[:skip]} to skip)"
9
+ if options.key? :skip
10
+ statement += if options[:skip].strip.empty?
11
+ ' (Enter to skip)'
12
+ else
13
+ " (#{options[:skip]} to skip)"
14
+ end
12
15
  end
13
- until correct_answer
14
- answers = answer_set.join(", ")
16
+ correct_answer answer_set, options, color, statement
17
+ end
18
+
19
+ def correct_answer(answer_set, options, color, statement)
20
+ result = nil
21
+
22
+ until result
23
+ answers = answer_set.join(', ')
15
24
  answer = ask_simply("#{statement} [#{answers}]", color, options)
16
- skipped = (options.has_key?(:skip) && (answer == options[:skip].chomp))
17
- correct_answer = answer_set.include?(answer) || skipped ? answer : nil
18
- say("Your response must be one of: [#{answers}]. Please try again.") unless correct_answer
25
+ skipped = (options.key?(:skip) && (answer == options[:skip].chomp))
26
+ result = answer_set.include?(answer) || skipped ? answer : nil
27
+ unless result
28
+ say("Your response must be one of: [#{answers}]. Please try again.")
29
+ end
19
30
  end
20
- correct_answer
21
- end
22
31
 
32
+ result
33
+ end
23
34
  end
24
35
  end
25
- end
36
+ end
@@ -1,14 +1,15 @@
1
1
  module ApacheCLI
2
+ # Top level comment for apache
2
3
  class Apache < Thor
3
4
  package_name 'Thorium | Apache'
4
5
 
5
6
  include Thor::Actions
6
7
 
7
- class_option :verbose, :type => :boolean, :default => true
8
- class_option :sudo, :type => :boolean, :default => true
9
- class_option :ctl_method, :enum => ['apachectl', 'apache2ctl', 'service'], :default => 'apachectl'
8
+ class_option :verbose, type: :boolean, default: true
9
+ class_option :sudo, type: :boolean, default: true
10
+ class_option :ctl_method, enum: %w(apachectl apache2ctl service), default: 'apachectl'
10
11
 
11
- desc "ctl [ARGS]", "Apache controller wrapper"
12
+ desc 'ctl [ARGS]', 'Apache controller wrapper'
12
13
  long_desc <<-LONGDESC
13
14
  `start` - Starts apache
14
15
  `stop` - Stops apache
@@ -20,11 +21,9 @@ module ApacheCLI
20
21
  def ctl(*args)
21
22
  command = "#{options[:ctl_method]} #{args * ' '}"
22
23
  command = 'sudo ' + command if options[:sudo]
23
- run(command, {:verbose => options[:verbose], :capture => false})
24
+ run command, verbose: options[:verbose], capture: false
24
25
  end
25
26
 
26
- no_commands {
27
-
28
- }
27
+ no_commands {}
29
28
  end
30
- end
29
+ end
@@ -0,0 +1 @@
1
+ # Common tasks TBA
@@ -1,45 +1,53 @@
1
1
  module GitCLI
2
+ # Git tasks package
3
+ # Listing and cloning of repositories (Github support included)
2
4
  class Git < Thor
3
5
  package_name 'Thorium | Git'
6
+ GH_API_URL = 'https://api.github.com'
4
7
 
5
8
  include Thor::Actions
6
9
 
7
- class_option :verbose, :type => :boolean, :default => 1
8
- @@gh_api_url = "https://api.github.com"
10
+ class_option :verbose, type: :boolean, default: 1
9
11
 
10
- desc "list", "Lists Github repositories"
12
+ desc 'list', 'Lists Github repositories'
11
13
  def list
12
14
  require 'json'
13
- gh_uname = ask("Enter Github username: ", :green)
15
+ gh_uname = ask('Enter Github username: ', :green)
14
16
  abort if gh_uname.empty?
15
17
  puts "\nFetching Github repositories (#{gh_uname})..."
16
- puts "------------------------------------------"
18
+ puts '------------------------------------------'
17
19
  @repos = get_gh_repos(gh_uname).each_with_index.map do |e, i|
18
- e.values_at("name", "ssh_url", "clone_url").unshift("[#{i+1}]")
20
+ e.values_at('name', 'ssh_url', 'clone_url').unshift("[#{i + 1}]")
19
21
  end
20
22
  print_table @repos
21
23
  end
22
24
 
23
- desc "clone", "Clones a repository from the list"
25
+ desc 'clone', 'Clones a repository from the list'
24
26
  def clone
25
27
  list
26
28
  # Do not do anything if list is empty
27
- ask_options = {limited_to: ("1".."#{@repos.size}").to_a, skip: ""}
28
- answer = ask("Which repository would you like to clone?", :green, ask_options)
29
+ ask_options = { limited_to: ('1'..@repos.size.to_s).to_a, skip: '' }
30
+ answer = ask('Which repository would you like to clone?', :green, ask_options)
29
31
  abort if answer == ask_options[:skip]
30
- protocol = ask("Select a protocol (ssh or https)?", :green, :limited_to => ["s", "h"])
31
- url = protocol == "s" ? @repos[answer.to_i-1][2] : @repos[answer-1][3]
32
+ protocol = ask('Select a protocol (ssh or https)?', :green, limited_to: %w(s h))
33
+ url = if protocol == 's'
34
+ @repos[answer.to_i - 1][2]
35
+ else
36
+ @repos[answer - 1][3]
37
+ end
32
38
  run "git clone #{url}"
33
39
  end
34
40
 
35
- no_commands {
41
+ no_commands do
42
+
43
+ private
36
44
  # Fetches Github repositories for a given user
37
45
  def get_gh_repos(uname)
38
- url = "#{@@gh_api_url}/users/#{uname}/repos"
46
+ url = "#{GH_API_URL}/users/#{uname}/repos"
39
47
  gh_repos_filepath = ENV['HOME'] + "/.thorium/gh_repos_#{uname}.json"
40
- get url, gh_repos_filepath, :verbose => false
48
+ get url, gh_repos_filepath, verbose: false
41
49
  JSON.parse File.read(gh_repos_filepath)
42
50
  end
43
- }
51
+ end
44
52
  end
45
- end
53
+ end
@@ -1,3 +1,4 @@
1
+ # Top level comment for thorium
1
2
  module Thorium
2
- VERSION = "0.3.3"
3
- end
3
+ VERSION = '0.3.4'
4
+ end
metadata CHANGED
@@ -1,27 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thorium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Stankevich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-22 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  description: Simple workflow automation toolkit.
@@ -49,12 +77,12 @@ require_paths:
49
77
  - lib
50
78
  required_ruby_version: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
- version: '0'
82
+ version: 2.0.0
55
83
  required_rubygems_version: !ruby/object:Gem::Requirement
56
84
  requirements:
57
- - - '>='
85
+ - - ">="
58
86
  - !ruby/object:Gem::Version
59
87
  version: '0'
60
88
  requirements: []