planter-cli 3.0.3 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/src/_README.md CHANGED
@@ -7,16 +7,39 @@
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
13
40
 
14
41
  If you run into errors, try `gem install --user-install planter-cli`, or as a last ditch effort, `sudo gem install planter-cli`.
15
42
 
16
- ### Optional
17
-
18
- If [Gum](https://github.com/charmbracelet/gum) is available it will be used for command line input.
19
-
20
43
  ## Configuration
21
44
 
22
45
  Planter's base configuration is in `~/.config/planter/planter.yml`. This file can contain any of the keys used in templates (see below) and will serve as a base configuration for all templates. Any key defined in this file will be overridden if it exists in a template.
@@ -42,7 +65,7 @@ Scripts can be executable files in any language, and receive the template direct
42
65
 
43
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.
44
67
 
45
- 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.
46
69
 
47
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/).
48
71
 
@@ -53,27 +76,32 @@ variables:
53
76
  - key: var_key
54
77
  prompt: Prompt text
55
78
  type: string # [string,paragraph,float,integer,number,date,choice] defaults to string
56
- # value: (force value, string can include %%variables%% and regexes will be replaced. For date type can be today, time, now, etc.)
79
+ value: # (force value, string can include %%variables%% and regexes will be replaced. For date type can be today, time, now, etc.)
57
80
  default: Untitled
58
81
  min: 1
59
82
  max: 5
83
+ date_format: "%Y-%m-%d" # can be any strftime format, will be applied to any date type
84
+ ```
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
+
88
+ A configuration can include additional keys:
89
+
90
+ ```yaml
60
91
  script: # array of scripts, args passed as [script and args] TEMPLATE_DIR PWD
61
92
  - process.py
62
93
  git_init: false # if true, initialize a git repository in the newly-planted directory
63
94
  files: # Dictionary for file handling (see [File-specific handling](#file-specific-handling))
64
95
  replacements: # Dictionary of pattern/replacments for regex substitution, see [Regex replacements](#regex-replacements)
65
- repo: # If a repository URL is provided, it will be pulled and duplicated instead of copying a file structure
96
+ repo: # If a repository URL is provided, it will be pulled and duplicated instead of copying an existing file structure
66
97
  ```
67
98
 
68
- #### Default values in template strings
69
-
70
- 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. 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%%`.
71
99
 
72
100
  #### Multiple choice type
73
101
 
74
102
  If the `type` is set to `choice`, then the key `choices` can contain a hash or array of choices. The key that accepts the choice should be surrounded with parenthesis (required for each choice).
75
103
 
76
- If a Hash is defined, each choice can have a result string:
104
+ If a Hash/Dictionary is defined, each choice can have a result string:
77
105
 
78
106
  ```yaml
79
107
  variables:
@@ -89,7 +117,9 @@ variables:
89
117
  (z)sh: "#! /bin/zsh"
90
118
  ```
91
119
 
92
- If an array is defined, the string of the choice will also be its result:
120
+ When a choice is selected from a dictionary, the result string will be inserted instead of the choice title.
121
+
122
+ If an array is defined, the string of the choice will also be its result (minus any parenthesis):
93
123
 
94
124
  ```yaml
95
125
  variables:
@@ -105,48 +135,35 @@ variables:
105
135
  - 1. zsh
106
136
  ```
107
137
 
108
- 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 for its placement in the list (starting with 1), and parenthesis aren't required.
109
-
110
- #### If/then logic
111
-
112
- A template can use if/then logic, which is useful with multiple choice types. It can be applied to any type, though.
113
-
114
- The format for if/then logic is:
115
-
116
- ```
117
- %%if KEY OPERATOR VALUE%%
118
- content
119
- %%else if KEY OPERATOR VALUE2%%
120
- content 2
121
- %%else%%
122
- content 3
123
- %%endif%%
124
- ```
125
-
126
- 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.
127
-
128
- The key should be an existing key defined in `variables`. The operator can be any of:
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.
129
139
 
130
- - `==` or `=` (equals)
131
- - `=~` (matches regex)
132
- - `*=` (contains)
133
- - `^=` (starts with)
134
- - `$=` (ends with)
135
- - `>` (greater than)
136
- - `>=` (greater than or equal)
137
- - `<` (less than)
138
- - `<=` (less than or equal)
139
-
140
- The value after the operator doesn't need to be quoted, anything after the operator will be compared to the value of the key.
140
+ `value:` and `default:` can include previous variables, with modifiers:
141
141
 
142
- Logic can be used on multiple lines like the example above, or on a single line (useful for filenames):
143
-
144
- ```
145
- %%project%%.%%if language == javascript%%js%%else if language == ruby%%rb%%else%%sh%%endif%%
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"
146
164
  ```
147
165
 
148
- Content within if/else blocks can contain variables.
149
-
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.
150
167
 
151
168
  ### File-specific handling
152
169
 
@@ -178,7 +195,17 @@ Merged content
178
195
 
179
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.
180
197
 
181
- If `ask` is specified, a memu 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.
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.
182
209
 
183
210
  ### Regex replacements
184
211
 
@@ -196,12 +223,75 @@ Replacements are performed on both file/directory names and file contents. This
196
223
 
197
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.
198
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
+
199
289
  ## Usage
200
290
 
201
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.
202
292
 
203
293
  ```
204
- Usage: planter [options] TEMPLATE
294
+ Usage: plant [options] TEMPLATE
205
295
  --defaults Accept default values for all variables
206
296
  -i, --in TARGET Plant in TARGET instead of current directory
207
297
  -o, --overwrite Overwrite existing files
@@ -224,7 +314,6 @@ Variables can be passed on the command line with `--var KEY:VALUE`. This flag ca
224
314
  ## Documentation
225
315
 
226
316
  - [YARD documentation][RubyDoc] is hosted by RubyDoc.info.
227
- - [Interactive documentation][Omniref] is hosted by Omniref.
228
317
 
229
318
  [RubyDoc]: http://www.rubydoc.info/gems/planter-cli
230
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.3
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-02 00:00:00.000000000 Z
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