bogo-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 939d20f0220b9c6656a476df0d427a695e1c4cfb
4
+ data.tar.gz: a3f290edba54bc8cdc1b7d31dd30194cb864a37a
5
+ SHA512:
6
+ metadata.gz: ce77a1f8fe38cb9f36d6afddee5be03c2780518a44573cc6270bd56ec92bb7b448d52ce8667aca52b3504721dc1db39d9e560099dbc5554413a9e351eb95e3ba
7
+ data.tar.gz: b858d8ffeee9a0d5cb348e8e0828c0e01a441b80e01708f20491f69a57fc5483f6a0e15daa3a84409e42399f8dc63bac705a59517fde1c7d0f07dbd8f77ad889
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## v0.1.0
2
+ * Initial release
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ ## Branches
4
+
5
+ ### `master` branch
6
+
7
+ The master branch is the current stable released version.
8
+
9
+ ### `develop` branch
10
+
11
+ The develop branch is the current edge of development.
12
+
13
+ ## Pull requests
14
+
15
+ * https://github.com/spox/bogo-cli/pulls
16
+
17
+ Please base all pull requests of the `develop` branch. Merges to
18
+ `master` only occur through the `develop` branch. Pull requests
19
+ based on `master` will likely be cherry picked.
20
+
21
+ ## Issues
22
+
23
+ Need to report an issue? Use the github issues:
24
+
25
+ * https://github.com/spox/bogo-cli/issues
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Chris Roberts
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Bogo CLI
2
+
3
+ A collection of CLI libraries.
4
+
5
+ ## Info
6
+ * Repository: https://github.com/spox/bogo-cli
data/bogo-cli.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'bogo-cli/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'bogo-cli'
5
+ s.version = Bogo::Cli::VERSION.version
6
+ s.summary = 'CLI Helper libraries'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'code@chrisroberts.org'
9
+ s.homepage = 'https://github.com/spox/bogo-cli'
10
+ s.description = 'CLI Helper libraries'
11
+ s.require_path = 'lib'
12
+ s.license = 'Apache 2.0'
13
+ s.add_dependency 'bogo'
14
+ s.add_dependency 'bogo-config'
15
+ s.add_dependency 'bogo-ui'
16
+ s.add_dependency 'slop'
17
+ s.files = Dir['lib/**/*'] + %w(bogo-cli.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
18
+ end
@@ -0,0 +1,96 @@
1
+ require 'bogo-ui'
2
+ require 'bogo-config'
3
+ require 'bogo-cli'
4
+
5
+ module Bogo
6
+ module Cli
7
+ # Abstract command class
8
+ class Command
9
+
10
+ # @return [Hash] options
11
+ attr_reader :options
12
+ # @return [Array] cli arguments
13
+ attr_reader :arguments
14
+ # @return [Ui]
15
+ attr_reader :ui
16
+
17
+ # Build new command instance
18
+ #
19
+ # @return [self]
20
+ def initialize(opts, args)
21
+ @options = opts.to_smash
22
+ @arguments = args
23
+ @ui = Ui.new(
24
+ opts.fetch(
25
+ :app_name,
26
+ self.class.name.split('::').first
27
+ )
28
+ )
29
+ load_config!
30
+ end
31
+
32
+ # Execute the command
33
+ #
34
+ # @return [TrueClass]
35
+ def execute!
36
+ raise NotImplementedError
37
+ end
38
+
39
+ protected
40
+
41
+ # Command specific options
42
+ #
43
+ # @return [Hash]
44
+ def opts
45
+ options.fetch(self.class.name.split('::').last.downcase, {})
46
+ end
47
+
48
+ # Load configuration file and merge opts
49
+ # on top of file values
50
+ #
51
+ # @return [Hash]
52
+ def load_config!
53
+ if(options[:config])
54
+ config = Bogo::Config.new(options[:config])
55
+ elsif(self.class.const_defined?(:DEFAULT_CONFIGURATION_FILES))
56
+ path = self.class.const_get(:DEFAULT_CONFIGURATION_FILES).detect do |check|
57
+ full_check = File.expand_path(check)
58
+ File.exists?(full_check)
59
+ end
60
+ config = Bogo::Config.new(path) if path
61
+ end
62
+ if(config)
63
+ @options = config.to_smash.deep_merge(options.to_smash)
64
+ end
65
+ options
66
+ end
67
+
68
+ # Wrap action within nice text. Output resulting Hash if provided
69
+ #
70
+ # @param msg [String] message of action in progress
71
+ # @yieldblock action to execute
72
+ # @yieldreturn [Hash] result to output
73
+ # @return [TrueClass]
74
+ def run_action(msg)
75
+ ui.info("#{msg}... ", :nonewline)
76
+ begin
77
+ result = yield
78
+ ui.puts ui.color('complete!', :green, :bold)
79
+ if(result.is_a?(Hash))
80
+ ui.puts '---> Results:'
81
+ result.each do |k,v|
82
+ ui.puts " #{ui.color("#{k}:", :bold)} #{v}"
83
+ end
84
+ end
85
+ rescue => e
86
+ ui.puts ui.color('error!', :red, :bold)
87
+ ui.error "Reason - #{e}"
88
+ raise
89
+ end
90
+ true
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,30 @@
1
+ require 'slop'
2
+ require 'bogo-cli'
3
+
4
+ module Bogo
5
+ module Cli
6
+ class Setup
7
+ class << self
8
+
9
+ # Wrap slop setup for consistent usage
10
+ #
11
+ # @yield Slop setup block
12
+ # @return [TrueClass]
13
+ def define(&block)
14
+ begin
15
+ Slop.parse(:help => true) do
16
+ instance_exec(&block)
17
+ end
18
+ rescue => e
19
+ if(ENV['DEBUG'])
20
+ $stderr.puts "ERROR: #{e.class}: #{e}\n#{e.backtrace.join("\n")}"
21
+ end
22
+ exit -1
23
+ end
24
+ true
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Bogo
2
+ module Cli
3
+ VERSION = Gem::Version.new('0.1.0')
4
+ end
5
+ end
data/lib/bogo-cli.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'bogo'
2
+ require 'bogo-cli/version'
3
+
4
+ module Bogo
5
+ module Cli
6
+ autoload :Command, 'bogo-cli/command'
7
+ autoload :Setup, 'bogo-cli/setup'
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bogo-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bogo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bogo-config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bogo-ui
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: CLI Helper libraries
70
+ email: code@chrisroberts.org
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - CHANGELOG.md
76
+ - CONTRIBUTING.md
77
+ - LICENSE
78
+ - README.md
79
+ - bogo-cli.gemspec
80
+ - lib/bogo-cli.rb
81
+ - lib/bogo-cli/command.rb
82
+ - lib/bogo-cli/setup.rb
83
+ - lib/bogo-cli/version.rb
84
+ homepage: https://github.com/spox/bogo-cli
85
+ licenses:
86
+ - Apache 2.0
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: CLI Helper libraries
108
+ test_files: []
109
+ has_rdoc: