rigit 0.1.0 → 0.1.1

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: f8076af9f15739de9c3b1fb2a14ec2cdf4294d231e71e7a145d4e6caf6c43eae
4
- data.tar.gz: 7e02b86550c1f344cda505558a4cf85ed61bf5c5a211052f3f324a7b60db87a9
3
+ metadata.gz: 587a5ce7b7cc4f78aed7b500eebc77d6a8cde3f0203dd662473bda17b6fd2dd4
4
+ data.tar.gz: 21317d234a17a214cc14cd4909916b91912beb4da5e72f99bf62becd8d7fd6c3
5
5
  SHA512:
6
- metadata.gz: bfe4ba68fe6c433e6111d6c2bf94c22b7f09c0f585147f8f262fff5f5fc4ad290e91aff5510b0d9e5d4e6ce657d288cdd6e3916d9a9d738dfd4cf8b2c2d4774e
7
- data.tar.gz: 61441041f37c51e0d7c739a20e053f716d0335b3f120dd040710e2b0373740b652d5eab2bdce7b5ead38ac69c494555b47f7ceeb47decce59efce8a5479e9ce6
6
+ metadata.gz: 1589fb24b1c56af3bd893c381466bdc59bd81e946b4108554b0b3faca4e5f3f05057cd73de3cd36b5a1c0813bbca50363360496c3f11ae7918006360c18ae609
7
+ data.tar.gz: 86969745861ee54ec697c5429bd0523dffd21f07f89651cc1b01bb1c76fded36486544e009bac3bdfa51d75b0bd88c0cae41cb04c31f7db05d3dc25571e775e9
data/README.md CHANGED
@@ -61,6 +61,7 @@ $ rig
61
61
  Usage:
62
62
  rig build RIG [PARAMS...]
63
63
  rig install RIG REPO
64
+ rig uninstall RIG
64
65
  rig update RIG
65
66
  rig info RIG
66
67
  rig list [SUBFOLDER]
@@ -165,6 +166,18 @@ There are two types of folders in a rig template.
165
166
  2. Conditional folders (`parameter=value`) - contents in these folders will
166
167
  only be copied if the user answerd `value` to the question `parameter`.
167
168
 
169
+ A typical rig folder looks like this:
170
+
171
+ myrig
172
+ |-- base
173
+ | |-- files
174
+ | `-- and-folders
175
+ |-- param=y
176
+ | |-- files
177
+ | `-- and-folders
178
+ |-- param=n
179
+ `-- config.yml
180
+
168
181
 
169
182
  ### Dynamic Tokens
170
183
 
data/bin/rig CHANGED
@@ -10,8 +10,11 @@ rescue Rigit::Exit => e
10
10
  say message unless message == 'Rigit::Exit'
11
11
  exit 1
12
12
  rescue Rigit::ConfigError => e
13
- say "#{e.class} - #{e.message}"
13
+ say "!txtred!#{e.class} - #{e.message}"
14
14
  exit 1
15
+ rescue Rigit::TemplateError => e
16
+ say "!txtred!#{e.class} - #{e.message}!txtrst!\nin !txtgrn!#{e.file}!txtrst!"
17
+ say "Are you escaping % characters as %%?" if e.message =~ /%/
15
18
  rescue TTY::Reader::InputInterrupt
16
19
  say "\nGoodbye"
17
20
  exit 1
@@ -1,20 +1,26 @@
1
+ require 'fileutils'
2
+ require 'colsole'
1
3
  require 'super_docopt'
4
+
2
5
  require 'rigit/version'
3
6
 
4
7
  require 'rigit/commands/build'
5
8
  require 'rigit/commands/info'
6
9
  require 'rigit/commands/install'
7
10
  require 'rigit/commands/list'
11
+ require 'rigit/commands/uninstall'
8
12
  require 'rigit/commands/update'
9
13
 
10
14
  module Rigit
15
+ # Handles command line execution using docopt.
11
16
  class CommandLine < SuperDocopt::Base
12
17
  version VERSION
13
18
  docopt File.expand_path 'docopt.txt', __dir__
14
- subcommands [:build, :install, :update, :info, :list]
19
+ subcommands [:build, :install, :uninstall, :update, :info, :list]
15
20
 
16
21
  include Commands::Build
17
22
  include Commands::Install
23
+ include Commands::Uninstall
18
24
  include Commands::Update
19
25
  include Commands::Info
20
26
  include Commands::List
@@ -1,11 +1,14 @@
1
- require 'colsole'
2
-
3
1
  module Rigit::Commands
2
+ # The {Build} module provides the {#build} command for the {CommandLine}
3
+ # module.
4
4
  module Build
5
+
6
+ # The command line +build+ command.
5
7
  def build
6
8
  BuildHandler.new(args).execute
7
9
  end
8
10
 
11
+ # Internal class to handle scaffolding for the {CommandLine} class.
9
12
  class BuildHandler
10
13
  attr_reader :args, :rig_name, :target_dir
11
14
 
@@ -1,11 +1,15 @@
1
- require 'colsole'
2
-
3
1
  module Rigit::Commands
2
+ # The {Info} module provides the {#info} command for the {CommandLine}
3
+ # module.
4
4
  module Info
5
+
6
+ # The command line +info+ command.
5
7
  def info
6
8
  InfoHandler.new(args).execute
7
9
  end
8
10
 
11
+ # Internal class to handle the display of metadata about a rig for the
12
+ # {CommandLine} class.
9
13
  class InfoHandler
10
14
  include Colsole
11
15
 
@@ -1,12 +1,13 @@
1
- require 'fileutils'
2
- require 'colsole'
3
-
4
1
  module Rigit::Commands
2
+ # The {Install} module provides the {#install} command for the
3
+ # {CommandLine} module.
5
4
  module Install
5
+ # The command line +install+ command.
6
6
  def install
7
7
  InstallHandler.new(args).execute
8
8
  end
9
9
 
10
+ # Internal class to handle rig installation for the {CommandLine} class.
10
11
  class InstallHandler
11
12
  include Colsole
12
13
 
@@ -36,7 +37,7 @@ module Rigit::Commands
36
37
  say " !txtpur!rig build #{rig_name}\n"
37
38
  else
38
39
  # :nocov:
39
- say "!txtred!Installation failed"
40
+ say "!txtred!Install failed"
40
41
  # :nocov:
41
42
  end
42
43
 
@@ -1,11 +1,15 @@
1
- require 'colsole'
2
-
3
1
  module Rigit::Commands
2
+ # The {List} module provides the {#list} command for the {CommandLine}
3
+ # module.
4
4
  module List
5
+
6
+ # The command line +list+ command.
5
7
  def list
6
8
  ListHandler.new(args).execute
7
9
  end
8
10
 
11
+ # Internal class to handle listing of available rigs for the
12
+ # {CommandLine} class.
9
13
  class ListHandler
10
14
  include Colsole
11
15
 
@@ -0,0 +1,67 @@
1
+ module Rigit::Commands
2
+ # The {Uninstall} module provides the {#uninstall} command for the
3
+ # {CommandLine} module.
4
+ module Uninstall
5
+ # The command line +uninstall+ command.
6
+ def uninstall
7
+ UninstallHandler.new(args).execute
8
+ end
9
+
10
+ # Internal class to handle rig removal for the {CommandLine} class.
11
+ class UninstallHandler
12
+ include Colsole
13
+
14
+ attr_reader :args, :rig_name
15
+
16
+ def initialize(args)
17
+ @args = args
18
+ @rig_name = args['RIG']
19
+ end
20
+
21
+ def execute
22
+ verify_dirs
23
+ uninstall
24
+ end
25
+
26
+ private
27
+
28
+ def uninstall
29
+ say "This will remove !txtgrn!#{rig_name}!txtrst! and delete\n#{target_path}"
30
+ continue = tty_prompt.yes? "Continue?", default: false
31
+ uninstall! if continue
32
+ end
33
+
34
+ def uninstall!
35
+ say "Uninstalling !txtgrn!#{rig_name}"
36
+ success = FileUtils.rm_rf target_path
37
+
38
+ if success
39
+ say "Rig uninstalled !txtgrn!successfully"
40
+ else
41
+ # :nocov:
42
+ say "!txtred!Uninstall failed"
43
+ # :nocov:
44
+ end
45
+ end
46
+
47
+ def rig
48
+ @rig ||= Rigit::Rig.new rig_name
49
+ end
50
+
51
+ def target_path
52
+ @target_path ||= rig.path
53
+ end
54
+
55
+ def tty_prompt
56
+ @tty_prompt ||= TTY::Prompt.new
57
+ end
58
+
59
+ def verify_dirs
60
+ if !rig.exist?
61
+ say "Rig !txtgrn!#{rig_name}!txtrst! is not installed"
62
+ raise Rigit::Exit
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,5 +1,3 @@
1
- require 'colsole'
2
-
3
1
  module Rigit::Commands
4
2
  module Update
5
3
  def update
@@ -2,9 +2,15 @@ require 'configatron/core'
2
2
  require 'yaml'
3
3
 
4
4
  module Rigit
5
+ # Handles the rig config file.
6
+ # Usage example:
7
+ #
8
+ # Config.load 'path/to.yml'
9
+ #
5
10
  class Config
6
11
  attr_reader :path
7
12
 
13
+ # Returns a new +configatron+ instance, after loading from a YAML file.
8
14
  def self.load(path)
9
15
  new(path).settings
10
16
  end
@@ -3,6 +3,7 @@ Rigit
3
3
  Usage:
4
4
  rig build RIG [PARAMS...]
5
5
  rig install RIG REPO
6
+ rig uninstall RIG
6
7
  rig update RIG
7
8
  rig info RIG
8
9
  rig list [SUBFOLDER]
@@ -19,6 +20,9 @@ Commands:
19
20
  install
20
21
  Clone a remote rig git repository and install it locally.
21
22
 
23
+ uninstall
24
+ Remove an installed rig.
25
+
22
26
  update
23
27
  Update an installed rig to its latest version.
24
28
 
@@ -51,6 +55,7 @@ Environment Variables:
51
55
  Examples:
52
56
  rig build gem name=mygem spec=y
53
57
  rig install example https://github.com/DannyBen/example-rig.git
58
+ rig uninstall example
54
59
  rig update example
55
60
  rig info example
56
61
  rig list
@@ -1,4 +1,14 @@
1
1
  module Rigit
2
2
  class Exit < StandardError; end
3
+
3
4
  class ConfigError < ArgumentError; end
5
+
6
+ class TemplateError < StandardError
7
+ attr_reader :file
8
+
9
+ def initialize(file, message='')
10
+ @file = file
11
+ super message
12
+ end
13
+ end
4
14
  end
@@ -1,9 +1,12 @@
1
1
  module Rigit
2
+ # A utility class that handles all +git+ operations.
2
3
  class Git
4
+ # Clones a git repo.
3
5
  def self.clone(repo, target_path)
4
6
  execute %Q[git clone #{repo} "#{target_path}"]
5
7
  end
6
8
 
9
+ # Pulls a git repo.
7
10
  def self.pull(target_path)
8
11
  Dir.chdir target_path do
9
12
  execute %Q[git pull]
@@ -1,6 +1,10 @@
1
1
  require 'tty-prompt'
2
2
 
3
3
  module Rigit
4
+ # Handles prompt request for user input in batch.
5
+ # This is a wrapper around +TTY::Prompt+ that gets all the params (typically
6
+ # from the rig config file), and asks the user for input one by one, while
7
+ # considering prefilled values.
4
8
  class Prompt
5
9
  attr_reader :params
6
10
 
@@ -8,6 +12,9 @@ module Rigit
8
12
  @params = params
9
13
  end
10
14
 
15
+ # Asks the user for input. If a +prefill+ hash is provided, it will be
16
+ # used for values, and skip asking the user to provide answers for the
17
+ # ones that are prefilled.
11
18
  def get_input(prefill={})
12
19
  result = {}
13
20
  params.each do |key, spec|
@@ -1,19 +1,27 @@
1
1
  module Rigit
2
+ # Handles "rigging" (scaffolding) of new projects from template rigs.
2
3
  class Rig
3
4
  attr_reader :name
4
5
 
6
+ # Returns the root path for all rigs. By default, it will be +~/.rigs+
7
+ # unless the +RIG_HOME+ environment variable is set.
5
8
  def self.home
6
9
  ENV['RIG_HOME'] ||= File.expand_path('.rigs', Dir.home)
7
10
  end
8
11
 
12
+ # Sets the +RIG_HOME+ environment variable, and the new root path for
13
+ # rigs.
9
14
  def self.home=(path)
10
15
  ENV['RIG_HOME'] = path
11
16
  end
12
17
 
18
+ # Returns a new instance of Rig. The +name+ argument should be the name
19
+ # of an existing (installed) rig.
13
20
  def initialize(name)
14
21
  @name = name
15
22
  end
16
23
 
24
+ # Builds the project from the template rig.
17
25
  def scaffold(arguments: {}, target_dir:'.', &block)
18
26
  scaffold_dir dir: "#{path}/base", arguments: arguments,
19
27
  target_dir: target_dir, &block
@@ -27,26 +35,32 @@ module Rigit
27
35
  end
28
36
  end
29
37
 
38
+ # Returns the full path to the rig template.
30
39
  def path
31
40
  "#{Rig.home}/#{name}"
32
41
  end
33
42
 
43
+ # Returns true if the rig path exists.
34
44
  def exist?
35
45
  Dir.exist? path
36
46
  end
37
47
 
48
+ # Returns true if the rig has a +config.yml+ file.
38
49
  def has_config?
39
50
  File.exist? config_file
40
51
  end
41
52
 
53
+ # Returns the path to the +config.yml+ file of the rig.
42
54
  def config_file
43
55
  "#{path}/config.yml"
44
56
  end
45
57
 
58
+ # Returns a +configatron+ instance.
46
59
  def config
47
60
  @config ||= Config.load(config_file)
48
61
  end
49
62
 
63
+ # Returns metadata about the rig, including all of its config values.
50
64
  def info
51
65
  {
52
66
  name: name,
@@ -65,7 +79,12 @@ module Rigit
65
79
 
66
80
  next if block_given? and !yield target_file
67
81
 
68
- content = File.read(file) % arguments
82
+ begin
83
+ content = File.read(file) % arguments
84
+ rescue ArgumentError => e
85
+ raise TemplateError.new file, e.message
86
+ end
87
+
69
88
  File.deep_write target_file, content
70
89
  end
71
90
  end
@@ -1,3 +1,3 @@
1
1
  module Rigit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rigit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-17 00:00:00.000000000 Z
11
+ date: 2018-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: super_docopt
@@ -207,6 +207,7 @@ files:
207
207
  - lib/rigit/commands/info.rb
208
208
  - lib/rigit/commands/install.rb
209
209
  - lib/rigit/commands/list.rb
210
+ - lib/rigit/commands/uninstall.rb
210
211
  - lib/rigit/commands/update.rb
211
212
  - lib/rigit/config.rb
212
213
  - lib/rigit/docopt.txt
@@ -216,7 +217,7 @@ files:
216
217
  - lib/rigit/prompt.rb
217
218
  - lib/rigit/rig.rb
218
219
  - lib/rigit/version.rb
219
- homepage: https://github.com/DannyBen/rigit
220
+ homepage: https://dannyben.github.io/rigit/
220
221
  licenses:
221
222
  - MIT
222
223
  metadata: {}
@@ -236,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
237
  version: '0'
237
238
  requirements: []
238
239
  rubyforge_project:
239
- rubygems_version: 2.7.3
240
+ rubygems_version: 2.7.6
240
241
  signing_key:
241
242
  specification_version: 4
242
243
  summary: Zero-coding project scaffolding