planter-cli 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.irbrc +2 -1
- data/.yardopts +1 -0
- data/CHANGELOG.md +20 -0
- data/README.md +131 -45
- data/bin/plant +5 -4
- data/lib/planter/array.rb +15 -1
- data/lib/planter/color.rb +7 -1
- data/lib/planter/config.rb +172 -0
- data/lib/planter/filelist.rb +12 -2
- data/lib/planter/numeric.rb +31 -0
- data/lib/planter/plant.rb +24 -17
- data/lib/planter/prompt.rb +23 -11
- data/lib/planter/script.rb +3 -3
- data/lib/planter/string.rb +150 -74
- data/lib/planter/tag.rb +38 -0
- data/lib/planter/version.rb +1 -1
- data/lib/planter.rb +39 -108
- data/lib/tty-spinner/lib/tty/spinner/multi.rb +3 -3
- data/planter-cli.gemspec +2 -0
- data/spec/cli_spec.rb +12 -2
- data/spec/planter/filelist_spec.rb +2 -2
- data/spec/planter/prompt_spec.rb +71 -0
- data/spec/planter/script_spec.rb +5 -4
- data/spec/planter/string_spec.rb +26 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/templates/test/_planter.yml +2 -0
- data/spec/templates/test/_scripts/plant.sh +3 -0
- data/src/_README.md +131 -45
- metadata +8 -2
data/src/_README.md
CHANGED
@@ -7,6 +7,33 @@
|
|
7
7
|
|
8
8
|
Plant a directory structure and files using templates.
|
9
9
|
|
10
|
+
<!--GITHUB-->
|
11
|
+
- [Planter](#planter)
|
12
|
+
- [Installation](#installation)
|
13
|
+
- [Configuration](#configuration)
|
14
|
+
- [Scripts](#scripts)
|
15
|
+
- [Templates](#templates)
|
16
|
+
- [Multiple choice type](#multiple-choice-type)
|
17
|
+
- [File-specific handling](#file-specific-handling)
|
18
|
+
- [If/then logic for file handling](#ifthen-logic-for-file-handling)
|
19
|
+
- [Regex replacements](#regex-replacements)
|
20
|
+
- [Finder Tags](#finder-tags)
|
21
|
+
- [Placeholders](#placeholders)
|
22
|
+
- [Default values in template strings](#default-values-in-template-strings)
|
23
|
+
- [Modifiers](#modifiers)
|
24
|
+
- [If/then logic](#ifthen-logic)
|
25
|
+
- [Usage](#usage)
|
26
|
+
- [Documentation](#documentation)
|
27
|
+
- [Development and Testing](#development-and-testing)
|
28
|
+
- [Source Code](#source-code)
|
29
|
+
- [Requirements](#requirements)
|
30
|
+
- [Rake](#rake)
|
31
|
+
- [Guard](#guard)
|
32
|
+
- [Contributing](#contributing)
|
33
|
+
- [License](#license)
|
34
|
+
- [Warranty](#warranty)
|
35
|
+
<!--END GITHUB-->
|
36
|
+
|
10
37
|
## Installation
|
11
38
|
|
12
39
|
gem install planter-cli
|
@@ -38,7 +65,7 @@ Scripts can be executable files in any language, and receive the template direct
|
|
38
65
|
|
39
66
|
Templates are directories found in `~/.config/planter/templates/[TEMPLATE_NAME]`. All files and directories inside of these template directories are copied when that template is called. Filenames, directory names, and file contents can all use template placeholders.
|
40
67
|
|
41
|
-
Template placeholders are defined with `%%KEY%%`, where key is the key defined in the `variables` section of the configuration. `%%KEY%%` placeholders can be used in directory/file names, and in the file contents. These work in any plain text or RTF format document, including XML, so they can be used in things like Scrivener templates and MindNode files as well.
|
68
|
+
Template placeholders are defined with `%%KEY%%`, where key is the key defined in the `variables` section of the configuration. `%%KEY%%` placeholders can be used in directory/file names, and in the file contents. These work in any plain text or RTF format document, including XML, so they can be used in things like Scrivener templates and MindNode files as well. See the subsections for info on default values and modifiers for template placeholders.
|
42
69
|
|
43
70
|
Each template contains a `_planter.yml` file that defines variables and other configuration options. The file format for all configuration files is [YAML](https://yaml.org/spec/1.2.2/).
|
44
71
|
|
@@ -49,12 +76,15 @@ variables:
|
|
49
76
|
- key: var_key
|
50
77
|
prompt: Prompt text
|
51
78
|
type: string # [string,paragraph,float,integer,number,date,choice] defaults to string
|
52
|
-
|
79
|
+
value: # (force value, string can include %%variables%% and regexes will be replaced. For date type can be today, time, now, etc.)
|
53
80
|
default: Untitled
|
54
81
|
min: 1
|
55
82
|
max: 5
|
83
|
+
date_format: "%Y-%m-%d" # can be any strftime format, will be applied to any date type
|
56
84
|
```
|
57
85
|
|
86
|
+
For the date type, value can be `today`, `now`, `tomorrow`, `last thursday`, etc. and natural language will be converted to a time. The formatting will be determined automatically based on the type of the value, e.g. "now" gets a time string, but "today" just gets a YYYY-mm-dd string. This can be modified using the `date_format` key, which accepts any [strftime](https://www.fabriziomusacchio.com/blog/2021-08-15-strftime_Cheat_Sheet/) value. You can also include a date format string in single parenthesis after a natural language date value, e.g. `value: "now 'This year: %Y'"`.
|
87
|
+
|
58
88
|
A configuration can include additional keys:
|
59
89
|
|
60
90
|
```yaml
|
@@ -66,9 +96,6 @@ replacements: # Dictionary of pattern/replacments for regex substitution, see [R
|
|
66
96
|
repo: # If a repository URL is provided, it will be pulled and duplicated instead of copying an existing file structure
|
67
97
|
```
|
68
98
|
|
69
|
-
#### Default values in template strings
|
70
|
-
|
71
|
-
In a template you can add a default value for a placholder by adding `%default value` to it. For example, `%%project%Default Project%%` will set the placeholder to `Default Project` if the variable value matches the default value in the configuration (or doesn't exist). This allows you to accept the default on the command line but have a different value inserted in the template. To use another variable in its place, use `$KEY` in the placeholder, e.g. `%%project%$title%%` will replace the `project` key with the value of `title` if the default is selected. Modifiers can be used on either side of the `%`, e.g. `%%project%$title:snake%%`.
|
72
99
|
|
73
100
|
#### Multiple choice type
|
74
101
|
|
@@ -108,48 +135,35 @@ variables:
|
|
108
135
|
- 1. zsh
|
109
136
|
```
|
110
137
|
|
111
|
-
If the choice starts with a number (as above), then a numeric list will be generated and typing the associated index number will accept that choice. Numeric lists are automatically numbered, so the preceding digit doesn't matter, as long as it's a digit. In this case a default can be defined with an integer (in the `defaults:` key) for its placement in the list (starting with 1), and parenthesis aren't required.
|
112
|
-
|
113
|
-
#### If/then logic
|
114
|
-
|
115
|
-
A template can use if/then logic, which is useful with multiple choice types. It can be applied to any type, though.
|
116
|
-
|
117
|
-
The format for if/then logic is:
|
118
|
-
|
119
|
-
```
|
120
|
-
%%if KEY OPERATOR VALUE%%
|
121
|
-
content
|
122
|
-
%%else if KEY OPERATOR VALUE2%%
|
123
|
-
content 2
|
124
|
-
%%else%%
|
125
|
-
content 3
|
126
|
-
%%endif%%
|
127
|
-
```
|
128
|
-
|
129
|
-
There should be no spaces around the comparison, e.g. `%% if language == javascript %%` won't work. The block must start with an `if` statement and end with `%%endif%%` or `%%end%%`. The `%%else%%` statement is optional -- if it doesn't exist then the entire block will be removed if no conditions are met.
|
138
|
+
If the choice starts with a number (as above), then a numeric list will be generated and typing the associated index number will accept that choice. Numeric lists are automatically numbered, so the preceding digit doesn't matter, as long as it's a digit, and only the first item needs a digit to trigger numbering. In this case a default can be defined with an integer (in the `defaults:` key) for its placement in the list (starting with 1), and parenthesis aren't required.
|
130
139
|
|
131
|
-
|
140
|
+
`value:` and `default:` can include previous variables, with modifiers:
|
132
141
|
|
133
|
-
|
134
|
-
-
|
135
|
-
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
-
|
141
|
-
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
142
|
+
```yaml
|
143
|
+
- variables:
|
144
|
+
- key: language
|
145
|
+
prompt: Programming language
|
146
|
+
type: choice
|
147
|
+
default: 2
|
148
|
+
choices:
|
149
|
+
- 1. ruby
|
150
|
+
- javascript
|
151
|
+
- python
|
152
|
+
- bash
|
153
|
+
- zsh
|
154
|
+
- key: shebang
|
155
|
+
prompt: Shebang line
|
156
|
+
type: choice
|
157
|
+
default: "%%language:first_letter:lowercase%%"
|
158
|
+
choices:
|
159
|
+
(r)uby: "#! /usr/bin/env ruby"
|
160
|
+
(j)avascript: "#! /usr/bin/env node"
|
161
|
+
(p)ython: "#! /usr/bin/env python"
|
162
|
+
(b)ash: "#! /bin/bash"
|
163
|
+
(z)sh: "#! /bin/zsh"
|
149
164
|
```
|
150
165
|
|
151
|
-
|
152
|
-
|
166
|
+
The above would define the `language` variable first, accepting `javascript` as default, then when displaying the menu for `shebang`, the language variable would have its first letter lowercased and set as the default option for the menu.
|
153
167
|
|
154
168
|
### File-specific handling
|
155
169
|
|
@@ -181,7 +195,17 @@ Merged content
|
|
181
195
|
|
182
196
|
By default files that already exist in the destination directory are not overwritten, and merging allows you to add missing parts to a Rakefile or Makefile, for example.
|
183
197
|
|
184
|
-
If `ask` is specified, a
|
198
|
+
If `ask` is specified, a menu will be provided on the command line asking how to handle a file. If the file doesn't already exist, you will be asked only whether to copy the file or not. If it does exist, `overwrite` and `merge` options will be added.
|
199
|
+
|
200
|
+
#### If/then logic for file handling
|
201
|
+
|
202
|
+
The operation for a file match can be an if/then statement. There are two formats for this.
|
203
|
+
|
204
|
+
First, you can simply write `OPERATION if VARIABLE COMP VALUE`, e.g. `copy if language == ruby`. This can have an `else` statement: `overwrite if language == ruby else copy`.
|
205
|
+
|
206
|
+
You can also format it as `if VARIABLE COMP VALUE: OPERATION; else: OPERATION`. This format allows `else if` statements, e.g. `if language == perl: copy;else if language == ruby: overwrite; else: ignore`.
|
207
|
+
|
208
|
+
Planter's if/then parsing does not handle parenthetical or boolean operations.
|
185
209
|
|
186
210
|
### Regex replacements
|
187
211
|
|
@@ -199,6 +223,69 @@ Replacements are performed on both file/directory names and file contents. This
|
|
199
223
|
|
200
224
|
If `preserve_tags` is set to `true` in the config (either base or template), then existing Finder tags on the file or folder will be copied to the new file when a template is planted.
|
201
225
|
|
226
|
+
### Placeholders
|
227
|
+
|
228
|
+
Placeholders are `%%VARIABLE%%` strings used in filenames and within the content of the files. At their most basic, this would just look like `%%project_name%%`. But you can supply default values, string modifiers, and even if/then logic.
|
229
|
+
|
230
|
+
#### Default values in template strings
|
231
|
+
|
232
|
+
In a template you can add a default value for a placholder by adding `%default value` to it. For example, `%%project%Default Project%%` will set the placeholder to `Default Project` if the variable value matches the default value in the configuration (or doesn't exist). This allows you to accept the default on the command line but have a different value inserted in the template. To use another variable in its place, use `$KEY` in the placeholder, e.g. `%%project%$title%%` will replace the `project` key with the value of `title` if the default is selected. Modifiers can be used on either side of the `%`, e.g. `%%project%$title:snake%%`.
|
233
|
+
|
234
|
+
#### Modifiers
|
235
|
+
|
236
|
+
A `%%variable%%` in a template can include modifiers that affect the output of the variable. These are added as `%%variable:MODIFIER%%` and multiple modifiers can be strung together, e.g. `%%language:lowercase:first_letter%%`. The available modifiers are (listed with available abbreviations):
|
237
|
+
|
238
|
+
- `snake` (`s`): snake_case the value
|
239
|
+
- `camel` (`cam`): camelCase the value
|
240
|
+
- `upper` (`u`): UPPERCASE the value
|
241
|
+
- `lower` (`l`, `d`): lowercase the value
|
242
|
+
- `title` (`t`): Title Case The Value
|
243
|
+
- `slug` or `file` (`sl`): slug-format-the-value
|
244
|
+
- `first_letter` (`fl`): Extract the first letter from the value
|
245
|
+
- `first_word` (`fw`): Extract the first word from the value
|
246
|
+
|
247
|
+
#### If/then logic
|
248
|
+
|
249
|
+
A template can use if/then logic, which is useful with multiple choice types. It can be applied to any type, though.
|
250
|
+
|
251
|
+
The format for if/then logic is:
|
252
|
+
|
253
|
+
```
|
254
|
+
%%if KEY OPERATOR VALUE%%
|
255
|
+
content
|
256
|
+
%%else if KEY OPERATOR VALUE2%%
|
257
|
+
content 2
|
258
|
+
%%else%%
|
259
|
+
content 3
|
260
|
+
%%endif%%
|
261
|
+
```
|
262
|
+
|
263
|
+
There should be no spaces around the comparison, e.g. `%% if language == javascript %%` won't work. The block must start with an `if` statement and end with `%%endif%%` or `%%end%%`. The `%%else%%` statement is optional -- if it doesn't exist then the entire block will be removed if no conditions are met.
|
264
|
+
|
265
|
+
The key should be an existing key defined in `variables`. The operator can be any of:
|
266
|
+
|
267
|
+
- `==` or `=` (equals)
|
268
|
+
- `=~` (matches regex)
|
269
|
+
- `*=` (contains)
|
270
|
+
- `^=` (starts with)
|
271
|
+
- `$=` (ends with)
|
272
|
+
- `>` (greater than)
|
273
|
+
- `>=` (greater than or equal)
|
274
|
+
- `<` (less than)
|
275
|
+
- `<=` (less than or equal)
|
276
|
+
|
277
|
+
Any of these operators can be inverted (negated) by preceding with an exclamation point, e.g. `!=` means `not equal` and `!*=` means `does not contain`.
|
278
|
+
|
279
|
+
The value after the operator doesn't need to be quoted, anything after the operator will be compared to the value of the key.
|
280
|
+
|
281
|
+
Logic can be used on multiple lines like the example above, or on a single line (useful for filenames):
|
282
|
+
|
283
|
+
|
284
|
+
%%project%%.%%if language == javascript%%js%%else if language == ruby%%rb%%else%%sh%%endif%%
|
285
|
+
|
286
|
+
|
287
|
+
Content within if/else blocks can contain variables. Planter's if/then parsing does not handle parenthetical or boolean operations.
|
288
|
+
|
202
289
|
## Usage
|
203
290
|
|
204
291
|
The executable for Planter is `plant`. You can run `plant TEMPLATE` in any directory and TEMPLATE will be planted in the current directory. You can also use `--in PATH` to plant in another directory.
|
@@ -227,7 +314,6 @@ Variables can be passed on the command line with `--var KEY:VALUE`. This flag ca
|
|
227
314
|
## Documentation
|
228
315
|
|
229
316
|
- [YARD documentation][RubyDoc] is hosted by RubyDoc.info.
|
230
|
-
- [Interactive documentation][Omniref] is hosted by Omniref.
|
231
317
|
|
232
318
|
[RubyDoc]: http://www.rubydoc.info/gems/planter-cli
|
233
319
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: planter-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
@@ -368,11 +368,13 @@ files:
|
|
368
368
|
- lib/planter.rb
|
369
369
|
- lib/planter/array.rb
|
370
370
|
- lib/planter/color.rb
|
371
|
+
- lib/planter/config.rb
|
371
372
|
- lib/planter/errors.rb
|
372
373
|
- lib/planter/file.rb
|
373
374
|
- lib/planter/fileentry.rb
|
374
375
|
- lib/planter/filelist.rb
|
375
376
|
- lib/planter/hash.rb
|
377
|
+
- lib/planter/numeric.rb
|
376
378
|
- lib/planter/plant.rb
|
377
379
|
- lib/planter/prompt.rb
|
378
380
|
- lib/planter/script.rb
|
@@ -472,6 +474,7 @@ files:
|
|
472
474
|
- spec/planter/filelist_spec.rb
|
473
475
|
- spec/planter/hash_spec.rb
|
474
476
|
- spec/planter/plant_spec.rb
|
477
|
+
- spec/planter/prompt_spec.rb
|
475
478
|
- spec/planter/script_spec.rb
|
476
479
|
- spec/planter/string_spec.rb
|
477
480
|
- spec/planter/symbol_spec.rb
|
@@ -482,6 +485,7 @@ files:
|
|
482
485
|
- spec/templates/test/%%project:snake%%.rtf
|
483
486
|
- spec/templates/test/Rakefile
|
484
487
|
- spec/templates/test/_planter.yml
|
488
|
+
- spec/templates/test/_scripts/plant.sh
|
485
489
|
- spec/templates/test/_scripts/test.sh
|
486
490
|
- spec/templates/test/_scripts/test_fail.sh
|
487
491
|
- spec/templates/test/test.rb
|
@@ -522,6 +526,7 @@ test_files:
|
|
522
526
|
- spec/planter/filelist_spec.rb
|
523
527
|
- spec/planter/hash_spec.rb
|
524
528
|
- spec/planter/plant_spec.rb
|
529
|
+
- spec/planter/prompt_spec.rb
|
525
530
|
- spec/planter/script_spec.rb
|
526
531
|
- spec/planter/string_spec.rb
|
527
532
|
- spec/planter/symbol_spec.rb
|
@@ -532,6 +537,7 @@ test_files:
|
|
532
537
|
- spec/templates/test/%%project:snake%%.rtf
|
533
538
|
- spec/templates/test/Rakefile
|
534
539
|
- spec/templates/test/_planter.yml
|
540
|
+
- spec/templates/test/_scripts/plant.sh
|
535
541
|
- spec/templates/test/_scripts/test.sh
|
536
542
|
- spec/templates/test/_scripts/test_fail.sh
|
537
543
|
- spec/templates/test/test.rb
|