app_archetype 1.2.8 → 1.4.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/Gemfile.lock +102 -73
- data/README.md +166 -29
- data/app_archetype.gemspec +22 -19
- data/bin/app_archetype +20 -0
- data/bin/archetype +1 -1
- data/lib/app_archetype/cli.rb +171 -139
- data/lib/app_archetype/commands/delete_template.rb +58 -0
- data/lib/app_archetype/commands/find_templates.rb +66 -0
- data/lib/app_archetype/commands/list_templates.rb +49 -0
- data/lib/app_archetype/commands/new_template.rb +42 -0
- data/lib/app_archetype/commands/open_manifest.rb +48 -0
- data/lib/app_archetype/commands/print_path.rb +20 -0
- data/lib/app_archetype/commands/print_template_variables.rb +67 -0
- data/lib/app_archetype/commands/print_version.rb +19 -0
- data/lib/app_archetype/commands/render_template.rb +178 -0
- data/lib/app_archetype/commands.rb +13 -0
- data/lib/app_archetype/generators.rb +4 -3
- data/lib/app_archetype/template/manifest.rb +17 -1
- data/lib/app_archetype/template_manager.rb +13 -6
- data/lib/app_archetype/version.rb +1 -1
- data/lib/app_archetype.rb +40 -23
- data/lib/core_ext/string.rb +18 -12
- data/scripts/create_new_command +32 -0
- data/scripts/generators/command/manifest.json +15 -0
- data/scripts/generators/command/template/lib/app_archetype/commands/{{command_name.snake_case}}.rb.hbs +17 -0
- data/spec/app_archetype/cli/presenters_spec.rb +99 -99
- data/spec/app_archetype/cli/prompts_spec.rb +291 -291
- data/spec/app_archetype/cli_spec.rb +296 -65
- data/spec/app_archetype/commands/delete_template_spec.rb +132 -0
- data/spec/app_archetype/commands/find_templates_spec.rb +130 -0
- data/spec/app_archetype/commands/list_templates_spec.rb +55 -0
- data/spec/app_archetype/commands/new_template_spec.rb +84 -0
- data/spec/app_archetype/commands/open_manifest_spec.rb +113 -0
- data/spec/app_archetype/commands/print_path_spec.rb +22 -0
- data/spec/app_archetype/commands/print_template_variables_spec.rb +158 -0
- data/spec/app_archetype/commands/print_version_spec.rb +21 -0
- data/spec/app_archetype/commands/render_template_spec.rb +479 -0
- data/spec/app_archetype/generators_spec.rb +1 -1
- data/spec/app_archetype/template/manifest_spec.rb +31 -1
- data/spec/app_archetype/template_manager_spec.rb +32 -0
- data/spec/app_archetype_spec.rb +65 -0
- metadata +155 -80
- data/lib/app_archetype/cli/presenters.rb +0 -106
- data/lib/app_archetype/cli/prompts.rb +0 -152
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
require 'highline'
|
|
2
|
-
|
|
3
|
-
module AppArchetype
|
|
4
|
-
class CLI < ::Thor
|
|
5
|
-
# CLI output presenters
|
|
6
|
-
module Prompts
|
|
7
|
-
##
|
|
8
|
-
# Variable prompt question. Asked when evaluating template
|
|
9
|
-
# variables
|
|
10
|
-
#
|
|
11
|
-
# @param [AppArchetype::Template::Variable] variable
|
|
12
|
-
#
|
|
13
|
-
# @return [Proc]
|
|
14
|
-
#
|
|
15
|
-
VAR_PROMPT_MESSAGE = lambda do |variable|
|
|
16
|
-
"\nEnter value for `#{variable.name}` variable\n\n"\
|
|
17
|
-
"DESCRIPTION: #{variable.description}\n"\
|
|
18
|
-
"TYPE: #{variable.type}\n"\
|
|
19
|
-
"DEFAULT: #{variable.default}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class <<self
|
|
23
|
-
##
|
|
24
|
-
# Prompt returns a TTY prompt object for asking the user
|
|
25
|
-
# questions.
|
|
26
|
-
#
|
|
27
|
-
# @return [HighLine]
|
|
28
|
-
def prompt
|
|
29
|
-
HighLine.new
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
##
|
|
33
|
-
# A yes/no prompt for asking the user a yes or no question.
|
|
34
|
-
#
|
|
35
|
-
# @return [Boolean]
|
|
36
|
-
#
|
|
37
|
-
def yes?(message)
|
|
38
|
-
prompt.ask("#{message} [Y/n]", String) { |input| input.strip == 'Y' }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
##
|
|
42
|
-
# Prompt for requesting user input.
|
|
43
|
-
#
|
|
44
|
-
# A default can be provided in the event the user does not
|
|
45
|
-
# provide an answer.
|
|
46
|
-
#
|
|
47
|
-
# Validator also performs type conversion by default it is
|
|
48
|
-
# a string
|
|
49
|
-
#
|
|
50
|
-
# @param message [String]
|
|
51
|
-
# @param default [Object]
|
|
52
|
-
# @param validator [Object|Lambda]
|
|
53
|
-
#
|
|
54
|
-
# @return [Object]
|
|
55
|
-
#
|
|
56
|
-
def ask(message, validator: String, default: nil)
|
|
57
|
-
resp = prompt.ask(message, validator)
|
|
58
|
-
return default if !default.nil? && resp.to_s.empty?
|
|
59
|
-
|
|
60
|
-
resp
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
##
|
|
64
|
-
# Y/N prompt to ensure user is sure they wish to delete
|
|
65
|
-
# the selected template
|
|
66
|
-
#
|
|
67
|
-
# @param [AppArchetype::Template::Manifest] manifest
|
|
68
|
-
#
|
|
69
|
-
# @return [Boolean]
|
|
70
|
-
def delete_template(manifest)
|
|
71
|
-
yes?(
|
|
72
|
-
"Are you sure you want to delete `#{manifest.name}`?"
|
|
73
|
-
)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
##
|
|
77
|
-
# Returns a variable prompt based on the type of variable
|
|
78
|
-
# required. Once prompt has been executed, the response is
|
|
79
|
-
# returned to the caller.
|
|
80
|
-
#
|
|
81
|
-
# When the value is set in the manifest, the set value is
|
|
82
|
-
# returned without a prompt.
|
|
83
|
-
#
|
|
84
|
-
# For boolean and integer variables, the relevant prompt
|
|
85
|
-
# function is called.
|
|
86
|
-
#
|
|
87
|
-
# By default the string variable prompt will be used.
|
|
88
|
-
#
|
|
89
|
-
# @param [AppArchetype::Template::Variable] var
|
|
90
|
-
#
|
|
91
|
-
# @return [Object]
|
|
92
|
-
#
|
|
93
|
-
def variable_prompt_for(var)
|
|
94
|
-
return var.value if var.value?
|
|
95
|
-
return boolean_variable_prompt(var) if var.type == 'boolean'
|
|
96
|
-
return integer_variable_prompt(var) if var.type == 'integer'
|
|
97
|
-
|
|
98
|
-
string_variable_prompt(var)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
##
|
|
102
|
-
# Prompt for boolean variable. This quizzes the user as to
|
|
103
|
-
# whether they want the variable set or not. The response
|
|
104
|
-
# is returned to the caller.
|
|
105
|
-
#
|
|
106
|
-
# @param [AppArchetype::Template::Variable] variable
|
|
107
|
-
#
|
|
108
|
-
# @return [Boolean]
|
|
109
|
-
#
|
|
110
|
-
def boolean_variable_prompt(variable)
|
|
111
|
-
yes?(
|
|
112
|
-
VAR_PROMPT_MESSAGE.call(variable)
|
|
113
|
-
)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
##
|
|
117
|
-
# Prompt for integer. This quizzes the user for their
|
|
118
|
-
# choice and then attempts to convert it to an integer.
|
|
119
|
-
#
|
|
120
|
-
# In the event a non integer value is entered, a
|
|
121
|
-
# RuntimeError is thrown.
|
|
122
|
-
#
|
|
123
|
-
# @param [AppArchetype::Template::Variable] variable
|
|
124
|
-
#
|
|
125
|
-
# @return [Integer]
|
|
126
|
-
#
|
|
127
|
-
def integer_variable_prompt(variable)
|
|
128
|
-
ask(
|
|
129
|
-
VAR_PROMPT_MESSAGE.call(variable),
|
|
130
|
-
default: variable.default,
|
|
131
|
-
validator: Integer
|
|
132
|
-
)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
##
|
|
136
|
-
# Prompt for a string. Asks user for input and returns
|
|
137
|
-
# it.
|
|
138
|
-
#
|
|
139
|
-
# @param [AppArchetype::Template::Variable] variable
|
|
140
|
-
#
|
|
141
|
-
# @return [String]
|
|
142
|
-
#
|
|
143
|
-
def string_variable_prompt(variable)
|
|
144
|
-
ask(
|
|
145
|
-
VAR_PROMPT_MESSAGE.call(variable),
|
|
146
|
-
default: variable.default
|
|
147
|
-
)
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
end
|