cli-mastermind 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8db2ac9239f2def0778c23ee6a02f8e9955d4de5acfb1247e024a108ab4ac260
4
- data.tar.gz: 3a532c3c20cb827a781852ab02062928bb5edb0408ffd3c02348c0b6175e2856
3
+ metadata.gz: b77931d1ca0f264d32626bd535ac1b865230156182f46e1c52eea2d77dac0684
4
+ data.tar.gz: 170465e4aed0ac88fb1faf9a586b70276f32dea2eec30f194b7edbc8cbce87dd
5
5
  SHA512:
6
- metadata.gz: 9cb69d8818573049fca65ef43d2b83c6d4931ca69a2d98ff87ec1d36c6002f1c15c7f7bb45daa687e796bf3ff117a348883ff9203f055576f59dcb9a70dbb834
7
- data.tar.gz: 2c24a20bedc2e188825393cc853da61e29668b78e6760cd378d10ff41a7a0716dbb857e08373d14ac5b53c59c4d29bd11c37c66027cac7a51f2b20ec3d83364b
6
+ metadata.gz: 98a87cf788c133fdc60d3ee14a0e356839c85f6b45ca9b95e490619126a511f261d81b949ae46cd16912d27325a214cbb27982be4d0eae830ec9074e41e92424
7
+ data.tar.gz: 7cf8df99f7168abb8510c87a24b9568d3e3cfec599424ab698279abec36f57ade58b51f4f812860f2d8101ade4fec76b1236150fef5e54877b91c40a45e29369
@@ -63,11 +63,16 @@ module CLI
63
63
  # Loads all plan files added using +add_plans+
64
64
  # @see Plan.load
65
65
  def load_plans
66
- @plans ||= @plan_files.reduce({}) do |hash, file|
66
+ @plans = {}
67
+
68
+ top_level_plan = Plan.new('temporary_plan')
69
+
70
+ @plan_files.each do |file|
67
71
  plans = Plan.load file
68
- plans.each { |plan| hash[plan.name] = plan }
69
- hash
72
+ top_level_plan.add_children plans
70
73
  end
74
+
75
+ @plans = top_level_plan.children
71
76
  end
72
77
 
73
78
  # Loads a masterplan using the DSL, if it exists and hasn't been loaded already
@@ -8,5 +8,8 @@ module CLI
8
8
  super "Unsupported file type: #{extension}"
9
9
  end
10
10
  end
11
+
12
+ class InvalidPlanError < Error
13
+ end
11
14
  end
12
15
  end
@@ -7,6 +7,9 @@ module CLI::Mastermind
7
7
  DSL.new(filename).plans
8
8
  end
9
9
 
10
+ class InvalidPlanfileError < Error
11
+ end
12
+
10
13
  private
11
14
 
12
15
  class DSL
@@ -14,21 +17,22 @@ module CLI::Mastermind
14
17
 
15
18
  def initialize(filename=nil, &block)
16
19
  @plans = []
20
+ @filename = filename
17
21
 
18
22
  if block_given?
19
23
  instance_eval(&block)
20
24
  elsif File.exists? filename
21
25
  instance_eval(File.read(filename), filename, 0)
22
26
  else
23
- raise 'Must provide valid path to a planfile or a block', Error
27
+ raise InvalidPlanfileError, 'Must provide valid path to a planfile or a block'
24
28
  end
25
29
  end
26
30
 
27
31
  def plot(name, &block)
28
- plan = Plan.new name, @description
32
+ plan = Plan.new name, @description, @filename
29
33
  @description = nil
30
34
  @plans << plan
31
- plan.add_children DSL.new(&block).plans
35
+ plan.add_children DSL.new(@filename, &block).plans
32
36
  end
33
37
  alias_method :namespace, :plot
34
38
 
@@ -38,7 +42,7 @@ module CLI::Mastermind
38
42
  alias_method :desc, :description
39
43
 
40
44
  def plan(name, &block)
41
- @plans << Plan.new(name, @description, &block)
45
+ @plans << Plan.new(name, @description, @filename, &block)
42
46
  @description = nil
43
47
  end
44
48
  alias_method :task, :plan
@@ -16,6 +16,9 @@ module CLI
16
16
  # Used in the interactive plan selector to display child plans
17
17
  attr_reader :children
18
18
 
19
+ # The file this plan was loaded from, if any
20
+ attr_reader :filename
21
+
19
22
  # Loads a particular plan from the filesystem.
20
23
  # @see Loader
21
24
  def self.load(filename)
@@ -24,9 +27,10 @@ module CLI
24
27
  loader.load(filename)
25
28
  end
26
29
 
27
- def initialize(name, description=nil, &block)
30
+ def initialize(name, description=nil, filename=nil, &block)
28
31
  @name = name.to_s.freeze
29
32
  @description = description.freeze
33
+ @filename = filename
30
34
  @block = block
31
35
  @children = {}
32
36
  end
@@ -39,8 +43,8 @@ module CLI
39
43
  alias_method :dig, :get_child
40
44
 
41
45
  def add_children(plans)
42
- raise 'Cannot add child plans to a plan with an action', InvalidPlanError unless @block.nil?
43
- plans.each { |plan| @children[plan.name] = plan }
46
+ raise InvalidPlanError, 'Cannot add child plans to a plan with an action' unless @block.nil?
47
+ plans.each(&method(:incorporate_plan))
44
48
  end
45
49
 
46
50
  def has_children?
@@ -56,6 +60,31 @@ module CLI
56
60
 
57
61
  private
58
62
 
63
+ def incorporate_plan(plan)
64
+ # If this namespace isn't taken just add the plan
65
+ if @children.has_key? plan.name
66
+
67
+ # Otherwise, we need to handle a name collision
68
+ existing_plan = @children[plan.name]
69
+
70
+ # If both plans have children, we merge them together
71
+ if existing_plan.has_children? and plan.has_children?
72
+ existing_plan.add_children plan.children.values
73
+
74
+ return existing_plan
75
+ end
76
+
77
+ # Otherwise, the plan defined later wins and overwrites the existing plan
78
+ warn <<~PLAN_COLLISON.strip
79
+ Plan name collision encountered when loading plans from "#{plan.filename}" that cannot be merged.
80
+ "#{plan.name}" was previously defined in "#{existing_plan.filename}".
81
+ Plans from "#{plan.filename}" will be used instead.
82
+ PLAN_COLLISON
83
+ end
84
+
85
+ @children[plan.name] = plan
86
+ end
87
+
59
88
  # Delegate configuration to the top-level configuration object
60
89
  def_delegator :'CLI::Mastermind', :configuration
61
90
  alias_method :config, :configuration
@@ -8,7 +8,7 @@ module CLI
8
8
  module VERSION
9
9
  RELEASE = 0
10
10
  MAJOR = 0
11
- MINOR = 2
11
+ MINOR = 3
12
12
  PATCH = nil
13
13
 
14
14
  STRING = [RELEASE, MAJOR, MINOR, PATCH].compact.join('.').freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli-mastermind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hall
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-16 00:00:00.000000000 Z
11
+ date: 2019-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-ui
@@ -70,17 +70,8 @@ executables:
70
70
  extensions: []
71
71
  extra_rdoc_files: []
72
72
  files:
73
- - ".gitignore"
74
- - ".masterplan"
75
- - ".rspec"
76
- - Gemfile
77
- - Gemfile.lock
78
73
  - LICENSE.txt
79
74
  - README.md
80
- - bin/console
81
- - bin/rspec
82
- - bin/setup
83
- - cli-mastermind.gemspec
84
75
  - exe/mastermind
85
76
  - lib/cli/mastermind.rb
86
77
  - lib/cli/mastermind/arg_parse.rb
@@ -91,8 +82,6 @@ files:
91
82
  - lib/cli/mastermind/loader/planfile_loader.rb
92
83
  - lib/cli/mastermind/plan.rb
93
84
  - lib/cli/mastermind/version.rb
94
- - plans/gem.plan
95
- - plans/sample.plan
96
85
  homepage: https://github.com/chall8908/cli-mastermind
97
86
  licenses:
98
87
  - MIT
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
@@ -1,6 +0,0 @@
1
- #-*- ruby -*-
2
- at_project_root
3
-
4
- has_plan_files
5
-
6
- configure(:gemspec) { Gem::Specification.load('cli-mastermind.gemspec') }
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- #ruby=ruby-2.5.1
6
- #ruby-gemset=cli-mastermind
7
-
8
- # Specify your gem's dependencies in cli-mastermind.gemspec
9
- gemspec
10
-
11
- gem 'pry'
12
- gem 'pry-byebug'
@@ -1,46 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- cli-mastermind (0.0.1)
5
- cli-ui (~> 1.2, >= 1.2.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- byebug (10.0.2)
11
- cli-ui (1.2.1)
12
- coderay (1.1.2)
13
- diff-lcs (1.3)
14
- method_source (0.9.2)
15
- pry (0.12.2)
16
- coderay (~> 1.1.0)
17
- method_source (~> 0.9.0)
18
- pry-byebug (3.6.0)
19
- byebug (~> 10.0)
20
- pry (~> 0.10)
21
- rspec (3.8.0)
22
- rspec-core (~> 3.8.0)
23
- rspec-expectations (~> 3.8.0)
24
- rspec-mocks (~> 3.8.0)
25
- rspec-core (3.8.0)
26
- rspec-support (~> 3.8.0)
27
- rspec-expectations (3.8.2)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.8.0)
30
- rspec-mocks (3.8.0)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.8.0)
33
- rspec-support (3.8.0)
34
-
35
- PLATFORMS
36
- ruby
37
-
38
- DEPENDENCIES
39
- bundler (~> 1.16)
40
- cli-mastermind!
41
- pry
42
- pry-byebug
43
- rspec (~> 3.0)
44
-
45
- BUNDLED WITH
46
- 1.16.2
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "cli/mastermind"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- require "pry"
11
- require 'pry-byebug'
12
- Pry.start
data/bin/rspec DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rspec' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rspec-core", "rspec")
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,34 +0,0 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "cli/mastermind/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "cli-mastermind"
7
- spec.version = CLI::Mastermind.gem_version
8
- spec.authors = ["Chris Hall"]
9
- spec.email = ["chall8908@gmail.com"]
10
-
11
- spec.summary = "Mastermind is a library for constructing command line toolboxes."
12
- spec.description = <<-DESC
13
- Take over the world from your command line!
14
- With mastermind, you can quickly build and generate
15
- command line toolkits without having to custom build
16
- everything for every project.
17
- DESC
18
- spec.homepage = "https://github.com/chall8908/cli-mastermind"
19
- spec.license = "MIT"
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
30
- spec.add_runtime_dependency "cli-ui", "~> 1.2", ">= 1.2.1"
31
-
32
- spec.add_development_dependency "bundler", "~> 1.16"
33
- spec.add_development_dependency "rspec", "~> 3.0"
34
- end
@@ -1,39 +0,0 @@
1
- #-*- ruby -*-
2
- plot :gem do
3
- description 'Builds the mastermind gem'
4
- # NOTE: The Gem::Package interface doesn't appear to be completely stable.
5
- # This may only work on version 2.7.7 of RubyGems, though other versions
6
- # seem to support passing only a spec as I'm doing here.
7
- plan :build do
8
- Dir.mkdir 'pkg' unless Dir.exists? 'pkg'
9
-
10
- require 'rubygems/package'
11
- spec = config.gemspec
12
-
13
- Gem::Package.build(spec)
14
-
15
- File.write(File.join('pkg', spec.file_name), File.read(spec.file_name), mode: ?w)
16
- File.delete(spec.file_name)
17
- end
18
-
19
- description 'Install mastermind into the local system'
20
- plan :install do
21
- require 'rubygems/installer'
22
- config.plans['gem']['build'].call
23
-
24
- Gem::Installer.at(File.join('pkg', config.gemspec.file_name)).install
25
- end
26
-
27
- description 'Package and push a new release'
28
- plan :release do
29
- config.plans['gem']['build'].call
30
- spec = config.gemspec
31
-
32
- `git tag '#{spec.version}'`
33
- `git push origin HEAD`
34
- `git push --tags`
35
-
36
- require 'rubygems/command_manager'
37
- Gem::CommandManager.instance['push'].invoke File.join('pkg', spec.file_name)
38
- end
39
- end
@@ -1,17 +0,0 @@
1
- #-*- ruby -*-
2
- # aliased as `namespace` for a less fanciful, rake-like way of doing things
3
- plot :top_level do
4
-
5
- # aliased as `desc` if you prefer brevity
6
- description 'This is the description of the next plan defined'
7
- # aliased as `task`, for a less fanciful, rake-like way of doing things
8
- plan :child_plan do |arguments|
9
- puts 'EXECUTING'
10
- puts arguments
11
- end
12
-
13
- description 'This is another plan under the top_level plan'
14
- plan :second_child do
15
- # more tasks
16
- end
17
- end