rbcli 0.2.1 → 0.2.2

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +13 -8
  5. data/Rakefile +5 -5
  6. data/bin/console +3 -3
  7. data/docs-src/docs/development/contributing.md +24 -0
  8. data/docs-src/docs/imported/changelog.md +23 -0
  9. data/docs-src/docs/imported/quick_reference.md +1 -0
  10. data/docs/development/contributing/index.html +15 -0
  11. data/docs/imported/changelog/index.html +120 -18
  12. data/docs/search/search_index.json +38 -8
  13. data/docs/sitemap.xml +19 -19
  14. data/lib/rbcli.rb +3 -22
  15. data/lib/rbcli/configuration/configurate.rb +49 -98
  16. data/lib/rbcli/{stateful_systems/configuratestorage.rb → configuration/configurate_blocks/hooks.rb} +23 -15
  17. data/lib/rbcli/configuration/configurate_blocks/me.rb +122 -0
  18. data/lib/rbcli/configuration/configurate_blocks/storage.rb +50 -0
  19. data/lib/rbcli/engine/command.rb +59 -60
  20. data/lib/rbcli/engine/parser.rb +17 -10
  21. data/lib/rbcli/{autoupdate → features/autoupdate/common}/autoupdate.rb +2 -20
  22. data/lib/rbcli/{autoupdate → features/autoupdate}/gem_updater.rb +1 -0
  23. data/lib/rbcli/{autoupdate → features/autoupdate}/github_updater.rb +1 -0
  24. data/lib/rbcli/{logging → features}/logging.rb +19 -18
  25. data/lib/rbcli/{remote_exec → features}/remote_exec.rb +0 -0
  26. data/lib/rbcli/{scriptwrapping → features}/scriptwrapper.rb +0 -29
  27. data/lib/rbcli/{configuration/config.rb → features/userconfig.rb} +0 -0
  28. data/lib/rbcli/{stateful_systems → state_storage/common}/state_storage.rb +0 -0
  29. data/lib/rbcli/{stateful_systems/storagetypes → state_storage}/localstate.rb +2 -10
  30. data/lib/rbcli/{stateful_systems/storagetypes → state_storage}/remote_state_connectors/dynamodb.rb +0 -0
  31. data/lib/rbcli/{stateful_systems/storagetypes → state_storage}/remotestate_dynamodb.rb +6 -20
  32. data/lib/rbcli/util/deprecation_warning.rb +43 -0
  33. data/lib/rbcli/version.rb +1 -1
  34. data/rbcli.gemspec +1 -1
  35. data/skeletons/micro/executable +5 -1
  36. data/skeletons/mini/executable +8 -8
  37. data/skeletons/project/Rakefile +2 -2
  38. data/skeletons/project/hooks/default_action.rb +1 -1
  39. data/skeletons/project/hooks/first_run.rb +1 -1
  40. data/skeletons/project/hooks/post_execution.rb +1 -1
  41. data/skeletons/project/hooks/pre_execution.rb +1 -1
  42. data/skeletons/project/spec/spec_helper.rb +2 -2
  43. metadata +17 -14
@@ -18,6 +18,7 @@
18
18
  # For questions regarding licensing, please contact andrew@blacknex.us #
19
19
  ##################################################################################
20
20
 
21
+ require 'rbcli/features/autoupdate/common/autoupdate'
21
22
  require 'net/http'
22
23
  require 'json'
23
24
 
@@ -18,6 +18,7 @@
18
18
  # For questions regarding licensing, please contact andrew@blacknex.us #
19
19
  ##################################################################################
20
20
 
21
+ require 'rbcli/features/autoupdate/common/autoupdate'
21
22
  require 'octokit'
22
23
 
23
24
  module Rbcli::Autoupdate
@@ -42,7 +42,7 @@ require 'colorize'
42
42
  module Rbcli::Logger
43
43
 
44
44
  @default_level = 'info'
45
- @default_target = 'stderr'
45
+ @default_target = nil
46
46
 
47
47
  def self.save_defaults level: nil, target: nil
48
48
  @default_level = level if level
@@ -61,27 +61,28 @@ module Rbcli::Logger
61
61
  end
62
62
  self.save_defaults
63
63
 
64
+ def self.make_logger
65
+ if Rbcli::config[:logger][:log_target].nil?
66
+ target = '/dev/null'
67
+ elsif Rbcli::config[:logger][:log_target].downcase == 'stdout'
68
+ target = STDOUT
69
+ elsif Rbcli::config[:logger][:log_target].downcase == 'stderr'
70
+ target = STDERR
71
+ else
72
+ target = Rbcli::config[:logger][:log_target]
73
+ end
74
+ @logger = Logger.new(target)
75
+ @logger.level = Rbcli::config[:logger][:log_level]
64
76
 
65
- if Rbcli::config[:logger][:log_target].downcase == 'stdout'
66
- target = STDOUT
67
- elsif Rbcli::config[:logger][:log_target].downcase == 'stderr'
68
- target = STDERR
69
- elsif Rbcli::config[:logger][:log_target].nil?
70
- target = '/dev/null'
71
- else
72
- target = Rbcli::config[:logger][:log_target]
73
- end
74
- target = '/dev/null' if Rbcli::config[:logger][:log_level].nil?
75
- @logger = Logger.new(target)
76
- @logger.level = Rbcli::config[:logger][:log_level]
77
-
78
- original_formatter = Logger::Formatter.new
79
- @logger.formatter = proc do |severity, datetime, progname, msg|
80
- original_formatter.call(severity, datetime, progname || caller_locations[3].path.split('/')[-1], msg.dump)
77
+ original_formatter = Logger::Formatter.new
78
+ @logger.formatter = proc do |severity, datetime, progname, msg|
79
+ original_formatter.call(severity, datetime, progname || caller_locations[3].path.split('/')[-1], msg.dump)
80
+ end
81
+ @logger
81
82
  end
82
83
 
83
84
  def self.log
84
- @logger
85
+ @logger || self.make_logger
85
86
  end
86
87
 
87
88
  end
File without changes
@@ -18,35 +18,6 @@
18
18
  # For questions regarding licensing, please contact andrew@blacknex.us #
19
19
  ##################################################################################
20
20
 
21
- class Rbcli::Command
22
- def self.extern path: nil, envvars: nil, &block
23
- if path == :default
24
- callerscript = caller_locations.first.absolute_path
25
- path = "#{File.dirname(callerscript)}/scripts/#{File.basename(callerscript, ".*")}.sh"
26
- end
27
- block = nil unless block_given?
28
- @extern = Rbcli::Scriptwrapper.new path, envvars, block
29
- end
30
-
31
- def extern
32
- @extern ||= nil
33
- self.class.instance_variable_get :@extern
34
- end
35
-
36
- def self.script path: nil, envvars: nil
37
- if path == :default or path.nil?
38
- callerscript = caller_locations.first.absolute_path
39
- path = "#{File.dirname(callerscript)}/scripts/#{File.basename(callerscript, ".*")}.sh"
40
- end
41
- @script = Rbcli::Scriptwrapper.new path, envvars, nil, true
42
- end
43
-
44
- def script
45
- @script ||= nil
46
- self.class.instance_variable_get :@script
47
- end
48
- end
49
-
50
21
  require 'json'
51
22
  class Rbcli::Scriptwrapper
52
23
  def initialize path, envvars = nil, block = nil, script = false
@@ -18,22 +18,14 @@
18
18
  # For questions regarding licensing, please contact andrew@blacknex.us #
19
19
  ##################################################################################
20
20
 
21
+ require 'rbcli/state_storage/common/state_storage'
21
22
  require 'fileutils'
22
23
  require 'json'
23
24
 
24
- ## Configuration Interface
25
- module Rbcli::ConfigurateStorage
26
- @data[:localstate] = nil
27
-
28
- def self.local_state path, force_creation: false, halt_on_error: false
29
- @data[:localstate] = Rbcli::State::LocalStorage.new(path, force_creation: force_creation, halt_on_error: halt_on_error)
30
- end
31
- end
32
-
33
25
  ## User Interface
34
26
  module Rbcli
35
27
  def self.local_state
36
- Rbcli::ConfigurateStorage.data[:localstate]
28
+ Rbcli.configuration(:storage, :localstate)
37
29
  end
38
30
  end
39
31
 
@@ -18,21 +18,7 @@
18
18
  # For questions regarding licensing, please contact andrew@blacknex.us #
19
19
  ##################################################################################
20
20
 
21
- ## Configuration Interface
22
- module Rbcli::ConfigurateStorage
23
- @data[:remotestate] = nil
24
- @data[:remotestate_init_params] = nil
25
-
26
- def self.remote_state_dynamodb table_name: nil, region: nil, force_creation: false, halt_on_error: true, locking: false
27
- raise StandardError "Must decalre `table_name` and `region` to use remote_state_dynamodb" if table_name.nil? or region.nil?
28
- @data[:remotestate_init_params] = {
29
- dynamodb_table: table_name,
30
- region: region,
31
- locking: locking
32
- }
33
- @data[:remotestate] = Rbcli::State::DynamoDBStorage.new(table_name, force_creation: force_creation, halt_on_error: halt_on_error)
34
- end
35
- end
21
+ require 'rbcli/state_storage/common/state_storage'
36
22
 
37
23
  ## User Interface
38
24
  module Rbcli
@@ -58,15 +44,15 @@ module Rbcli::State
58
44
  # end
59
45
 
60
46
  def state_subsystem_init
61
- @locking = Rbcli::ConfigurateStorage::data[:remotestate_init_params][:locking]
62
- dynamodb_table = Rbcli::ConfigurateStorage::data[:remotestate_init_params][:dynamodb_table]
63
- region = Rbcli::ConfigurateStorage::data[:remotestate_init_params][:region]
47
+ @locking = Rbcli.configuration(:storage, :remotestate_init_params)[:locking]
48
+ dynamodb_table = Rbcli.configuration(:storage, :remotestate_init_params)[:dynamodb_table]
49
+ region = Rbcli.configuration(:storage, :remotestate_init_params)[:region]
64
50
 
65
51
  # Set defaults in Rbcli's config
66
52
  Rbcli::State::RemoteConnectors::DynamoDB.save_defaults
67
53
 
68
54
  # Create DynamoDB Connector
69
- @dynamodb = Rbcli::State::RemoteConnectors::DynamoDB.new dynamodb_table, region, Rbcli::config[:aws_access_key_id], Rbcli::config[:aws_secret_access_key], locking: Rbcli::ConfigurateStorage::data[:remotestate_init_params][:locking]
55
+ @dynamodb = Rbcli::State::RemoteConnectors::DynamoDB.new dynamodb_table, region, Rbcli::config[:aws_access_key_id], Rbcli::config[:aws_secret_access_key], locking: Rbcli.configuration(:storage, :remotestate_init_params)[:locking]
70
56
  end
71
57
 
72
58
  def state_exists?
@@ -126,4 +112,4 @@ module Rbcli::State
126
112
  end
127
113
 
128
114
 
129
- require 'rbcli/stateful_systems/storagetypes/remote_state_connectors/dynamodb'
115
+ require 'rbcli/state_storage/remote_state_connectors/dynamodb'
@@ -0,0 +1,43 @@
1
+ ##################################################################################
2
+ # RBCli -- A framework for developing command line applications in Ruby #
3
+ # Copyright (C) 2018 Andrew Khoury #
4
+ # #
5
+ # This program is free software: you can redistribute it and/or modify #
6
+ # it under the terms of the GNU General Public License as published by #
7
+ # the Free Software Foundation, either version 3 of the License, or #
8
+ # (at your option) any later version. #
9
+ # #
10
+ # This program is distributed in the hope that it will be useful, #
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
13
+ # GNU General Public License for more details. #
14
+ # #
15
+ # You should have received a copy of the GNU General Public License #
16
+ # along with this program. If not, see <https://www.gnu.org/licenses/>. #
17
+ # #
18
+ # For questions regarding licensing, please contact andrew@blacknex.us #
19
+ ##################################################################################
20
+
21
+
22
+ class Rbcli::DeprecationWarning
23
+
24
+ @@warnings = []
25
+
26
+ def initialize original_feature_name, message_text, change_by_version
27
+ #@caller = caller_locations(2,1)[0].label
28
+ @original_feature_name = original_feature_name
29
+ @message_text = message_text
30
+ @change_by_version = change_by_version
31
+ @@warnings.append self
32
+ end
33
+
34
+ def display
35
+ message = "DEPRECATION WRNING: The feature `#{@original_feature_name}` has been deprecated. #{@message_text} This feature will be removed in version #{@change_by_version}."
36
+ Rbcli::log.warn { message }
37
+ puts message.red
38
+ end
39
+
40
+ def self.display_warnings
41
+ @@warnings.each { |w| w.display }
42
+ end
43
+ end
data/lib/rbcli/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
  ##################################################################################
20
20
 
21
21
  module Rbcli
22
- VERSION = "0.2.1"
22
+ VERSION = "0.2.2"
23
23
  end
data/rbcli.gemspec CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  lib = File.expand_path("../lib", __FILE__)
22
22
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
23
- require "rbcli/version"
23
+ require 'rbcli/version'
24
24
 
25
25
  Gem::Specification.new do |spec|
26
26
  spec.name = 'rbcli'
@@ -49,8 +49,12 @@ Rbcli::Configurate.me do
49
49
 
50
50
  ## Option -- (Optional, Multiple) -- Add a global CLI Option
51
51
  option :name, 'Give me your name', type: :string, default: 'Foo', required: false, permitted: ['Jack', 'Jill']
52
+ end
52
53
 
53
-
54
+ ###############################
55
+ ## Hooks Configuration Block ##
56
+ ###############################
57
+ Rbcli::Configurate.hooks do
54
58
  ## Default Action -- (Optional) -- The default code to execute when no subcommand is given.
55
59
  default_action do |opts|
56
60
  puts "Hello, #{opts[:name]}."
@@ -131,15 +131,15 @@ Rbcli::Configurate.me do
131
131
 
132
132
  ## Option -- (Optional, Multiple) -- Add a global CLI Option
133
133
  option :name, 'Give me your name', type: :string, default: 'Foo', required: false, permitted: ['Jack', 'Jill']
134
+ end
134
135
 
135
-
136
- ####
137
- # HOOKS
138
- ###
139
- # Here you can set hooks that will be run at specified points in the execution chain.
140
- # Global CLI options are made available to many of the hooks, but command parameters and lineitems are not.
141
- ###
142
-
136
+ ###############################
137
+ ## Hooks Configuration Block ##
138
+ ###############################
139
+ # Here you can set hooks that will be run at specified points in the execution chain.
140
+ # Global CLI options are made available to many of the hooks, but command parameters and lineitems are not.
141
+ ###############################
142
+ Rbcli::Configurate.hooks do
143
143
  ## Default Action -- (Optional) -- The default code to execute when no subcommand is given.
144
144
  # If not present, the help is shown (same as -h)
145
145
  default_action do |opts|
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
@@ -1,4 +1,4 @@
1
- Rbcli::Configurate.me do
1
+ Rbcli::Configurate.hooks do
2
2
  ####
3
3
  # HOOKS
4
4
  ###
@@ -1,4 +1,4 @@
1
- Rbcli::Configurate.me do
1
+ Rbcli::Configurate.hooks do
2
2
  ####
3
3
  # HOOKS
4
4
  ###
@@ -1,4 +1,4 @@
1
- Rbcli::Configurate.me do
1
+ Rbcli::Configurate.hooks do
2
2
  ####
3
3
  # HOOKS
4
4
  ###
@@ -1,4 +1,4 @@
1
- Rbcli::Configurate.me do
1
+ Rbcli::Configurate.hooks do
2
2
  ####
3
3
  # HOOKS
4
4
  ###
@@ -1,5 +1,5 @@
1
- require "bundler/setup"
2
- require "untitled"
1
+ require 'bundler/setup'
2
+ require 'untitled'
3
3
 
4
4
  RSpec.configure do |config|
5
5
  # Enable flags like --only-failures and --next-failure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Khoury
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-08 00:00:00.000000000 Z
11
+ date: 2018-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -284,22 +284,25 @@ files:
284
284
  - lib/rbcli-tool/project.rb
285
285
  - lib/rbcli-tool/util.rb
286
286
  - lib/rbcli.rb
287
- - lib/rbcli/autoupdate/autoupdate.rb
288
- - lib/rbcli/autoupdate/gem_updater.rb
289
- - lib/rbcli/autoupdate/github_updater.rb
290
- - lib/rbcli/configuration/config.rb
291
287
  - lib/rbcli/configuration/configurate.rb
288
+ - lib/rbcli/configuration/configurate_blocks/hooks.rb
289
+ - lib/rbcli/configuration/configurate_blocks/me.rb
290
+ - lib/rbcli/configuration/configurate_blocks/storage.rb
292
291
  - lib/rbcli/engine/command.rb
293
292
  - lib/rbcli/engine/load_project.rb
294
293
  - lib/rbcli/engine/parser.rb
295
- - lib/rbcli/logging/logging.rb
296
- - lib/rbcli/remote_exec/remote_exec.rb
297
- - lib/rbcli/scriptwrapping/scriptwrapper.rb
298
- - lib/rbcli/stateful_systems/configuratestorage.rb
299
- - lib/rbcli/stateful_systems/state_storage.rb
300
- - lib/rbcli/stateful_systems/storagetypes/localstate.rb
301
- - lib/rbcli/stateful_systems/storagetypes/remote_state_connectors/dynamodb.rb
302
- - lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb
294
+ - lib/rbcli/features/autoupdate/common/autoupdate.rb
295
+ - lib/rbcli/features/autoupdate/gem_updater.rb
296
+ - lib/rbcli/features/autoupdate/github_updater.rb
297
+ - lib/rbcli/features/logging.rb
298
+ - lib/rbcli/features/remote_exec.rb
299
+ - lib/rbcli/features/scriptwrapper.rb
300
+ - lib/rbcli/features/userconfig.rb
301
+ - lib/rbcli/state_storage/common/state_storage.rb
302
+ - lib/rbcli/state_storage/localstate.rb
303
+ - lib/rbcli/state_storage/remote_state_connectors/dynamodb.rb
304
+ - lib/rbcli/state_storage/remotestate_dynamodb.rb
305
+ - lib/rbcli/util/deprecation_warning.rb
303
306
  - lib/rbcli/util/hash_deep_symbolize.rb
304
307
  - lib/rbcli/util/string_colorize.rb
305
308
  - lib/rbcli/util/trollop.rb