Skip to content

Commit f8d5647

Browse files
committed
Rename directory to dir
This affects the command line option, the config file, and the template rendering context. An alias is provided in the config file and the template rendering context, so use of `directory` will still work here.
1 parent ce4d8e2 commit f8d5647

File tree

7 files changed

+195
-212
lines changed

7 files changed

+195
-212
lines changed

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,8 @@ github = "sindresorhus/pure"
269269
proto = "ssh"
270270
```
271271

272-
For a plain Git source you should specify the URL with a `git://` or `ssh://`
273-
protocol. For SSH you will need to specify the username as well (it is `git` for
274-
GitHub).
272+
For a plain Git source you should specify the URL with a `git://` or `ssh://` «.
273+
For SSH you will need to specify the username as well (it is `git` for GitHub).
275274

276275
```toml
277276
[plugins.pure]
@@ -295,7 +294,7 @@ remote = "https://github.com/rossmacarthur/pure/raw/master/pure.zsh"
295294
### Local
296295

297296
Local sources reference local directories. A Local source must set the `local`
298-
field and specify a `directory`. Tildes may be used and will be expanded to the
297+
field and specify a directory. Tildes may be used and will be expanded to the
299298
current user's home directory.
300299

301300
```toml
@@ -366,10 +365,10 @@ As template strings they could be represented like this
366365
```toml
367366
[templates]
368367
source = { value = 'source "{{ filename }}"', each = true }
369-
PATH = 'export PATH="{{ directory }}:$PATH"'
370-
FPATH = 'export FPATH="{{ directory }}:$FPATH"'
371-
path = 'path=( "{{ directory }}" $path )'
372-
fpath = 'fpath=( "{{ directory }}" $fpath )'
368+
PATH = 'export PATH="{{ dir }}:$PATH"'
369+
FPATH = 'export FPATH="{{ dir }}:$FPATH"'
370+
path = 'path=( "{{ dir }}" $path )'
371+
fpath = 'fpath=( "{{ dir }}" $fpath )'
373372
```
374373

375374
For example if we change the `apply` field for the below plugin, it will only
@@ -398,8 +397,8 @@ Plugins all have the following information that can be used in templates
398397
for the plugin in the plugins table. However, it is often the name of the
399398
plugin, so it can be useful to use this name in templates with `{{ name }}`.
400399
- **A directory.** In git sources this is the location of the cloned repository,
401-
for local sources, it is the `directory` specified. This `directory` can be
402-
used in templates with `{{ directory }}`.
400+
for local sources, it is the directory specified. This directory can be used
401+
in templates with `{{ dir }}`.
403402
- **Zero or more filenames.** These are the matched files in the plugin
404403
directory either discovered using the the global `match` field or specified as
405404
a plugin option with `use`. These can be used in templates using `{{ filename
@@ -435,7 +434,7 @@ do this like this
435434

436435
```toml
437436
[templates]
438-
PATH = 'export PATH="$PATH:{{ directory }}"'
437+
PATH = 'export PATH="$PATH:{{ dir }}"'
439438
```
440439

441440
You can then apply it to the plugin like this

src/cli.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct Add {
8080

8181
/// Which sub directory to use in this plugin.
8282
#[structopt(long, value_name = "PATH")]
83-
directory: Option<String>,
83+
dir: Option<String>,
8484

8585
/// Which files to use in this plugin.
8686
#[structopt(long = "use", value_name = "MATCH")]
@@ -214,7 +214,7 @@ impl Plugin {
214214
branch,
215215
rev,
216216
tag,
217-
directory,
217+
dir,
218218
uses,
219219
apply,
220220
} = add;
@@ -240,7 +240,7 @@ impl Plugin {
240240
inline: None,
241241
proto,
242242
reference,
243-
directory,
243+
dir,
244244
uses,
245245
apply,
246246
}),
@@ -524,7 +524,7 @@ OPTIONS:
524524
--branch <BRANCH> Checkout the tip of a branch
525525
--rev <SHA> Checkout a specific commit
526526
--tag <TAG> Checkout a specific tag
527-
--directory <PATH> Which sub directory to use in this plugin
527+
--dir <PATH> Which sub directory to use in this plugin
528528
--use <MATCH>... Which files to use in this plugin
529529
--apply <TEMPLATE>... Templates to apply to this plugin
530530
@@ -558,7 +558,7 @@ ARGS:
558558
"https://github.com/rossmacarthur/sheldon-test",
559559
"--rev",
560560
"ad149784a1538291f2477fb774eeeed4f4d29e45",
561-
"--directory",
561+
"--dir",
562562
"missing",
563563
"--use",
564564
"{name}.sh",
@@ -583,7 +583,7 @@ ARGS:
583583
branch: None,
584584
rev: Some("ad149784a1538291f2477fb774eeeed4f4d29e45".into()),
585585
tag: None,
586-
directory: Some("missing".into()),
586+
dir: Some("missing".into()),
587587
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
588588
apply: Some(vec_into!["something", "another-thing"]),
589589
}))
@@ -603,7 +603,7 @@ ARGS:
603603
"0.1.0",
604604
"--proto",
605605
"ssh",
606-
"--directory",
606+
"--dir",
607607
"missing",
608608
"--use",
609609
"{name}.sh",
@@ -624,7 +624,7 @@ ARGS:
624624
branch: None,
625625
rev: None,
626626
tag: Some("0.1.0".into()),
627-
directory: Some("missing".into()),
627+
dir: Some("missing".into()),
628628
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
629629
apply: Some(vec_into!["something", "another-thing"]),
630630
}))
@@ -644,7 +644,7 @@ ARGS:
644644
"feature",
645645
"--proto",
646646
"https",
647-
"--directory",
647+
"--dir",
648648
"missing",
649649
"--use",
650650
"{name}.sh",
@@ -665,7 +665,7 @@ ARGS:
665665
branch: Some("feature".into()),
666666
rev: None,
667667
tag: None,
668-
directory: Some("missing".into()),
668+
dir: Some("missing".into()),
669669
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
670670
apply: Some(vec_into!["something", "another-thing"]),
671671
}))
@@ -700,7 +700,7 @@ ARGS:
700700
branch: None,
701701
rev: None,
702702
tag: None,
703-
directory: None,
703+
dir: None,
704704
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
705705
apply: Some(vec_into!["something", "another-thing"]),
706706
}))
@@ -735,7 +735,7 @@ ARGS:
735735
branch: None,
736736
rev: None,
737737
tag: None,
738-
directory: None,
738+
dir: None,
739739
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
740740
apply: Some(vec_into!["something", "another-thing"]),
741741
}))

src/config.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub enum Source {
8686
/// A remote file.
8787
Remote { url: Url },
8888
/// A local directory.
89-
Local { directory: PathBuf },
89+
Local { dir: PathBuf },
9090
}
9191

9292
/// The actual plugin configuration.
@@ -114,7 +114,8 @@ pub struct RawPlugin {
114114
/// Which directory to use in this plugin.
115115
///
116116
/// This directory can contain template parameters.
117-
pub directory: Option<String>,
117+
#[serde(alias = "directory")]
118+
pub dir: Option<String>,
118119
/// Which files to use in this plugin's directory. If this is `None` then
119120
/// this will figured out based on the global `matches` field.
120121
///
@@ -134,7 +135,7 @@ pub struct ExternalPlugin {
134135
/// Specifies how to retrieve this plugin.
135136
pub source: Source,
136137
/// Which directory to use in this plugin.
137-
pub directory: Option<String>,
138+
pub dir: Option<String>,
138139
/// What files to use in the plugin's directory.
139140
pub uses: Option<Vec<String>>,
140141
/// What templates to apply to each matched file.
@@ -526,7 +527,7 @@ impl RawPlugin {
526527
inline,
527528
proto,
528529
reference,
529-
directory,
530+
dir,
530531
uses,
531532
apply,
532533
} = self;
@@ -568,8 +569,8 @@ impl RawPlugin {
568569
TempSource::External(Source::Remote { url })
569570
}
570571
// `local` type
571-
(None, None, None, None, Some(directory), None) => {
572-
TempSource::External(Source::Local { directory })
572+
(None, None, None, None, Some(dir), None) => {
573+
TempSource::External(Source::Local { dir })
573574
}
574575
// `inline` type
575576
(None, None, None, None, None, Some(raw)) => TempSource::Inline(raw),
@@ -597,7 +598,7 @@ impl RawPlugin {
597598
Ok(Plugin::External(ExternalPlugin {
598599
name,
599600
source,
600-
directory,
601+
dir,
601602
uses,
602603
apply,
603604
}))
@@ -606,7 +607,7 @@ impl RawPlugin {
606607
let unsupported = [
607608
("`proto` field is", proto.is_some()),
608609
("`branch`, `tag`, and `rev` fields are", is_reference_some),
609-
("`directory` field is", directory.is_some()),
610+
("`dir` field is", dir.is_some()),
610611
("`use` field is", uses.is_some()),
611612
("`apply` field is", apply.is_some()),
612613
];
@@ -912,7 +913,7 @@ mod tests {
912913
url: url.clone(),
913914
reference: None,
914915
},
915-
directory: None,
916+
dir: None,
916917
uses: None,
917918
apply: None,
918919
});
@@ -935,7 +936,7 @@ mod tests {
935936
url: Url::parse("git://gist.github.com/579d02802b1cc17baed07753d09f5009").unwrap(),
936937
reference: None,
937938
},
938-
directory: None,
939+
dir: None,
939940
uses: None,
940941
apply: None,
941942
});
@@ -964,7 +965,7 @@ mod tests {
964965
.unwrap(),
965966
reference: None,
966967
},
967-
directory: None,
968+
dir: None,
968969
uses: None,
969970
apply: None,
970971
});
@@ -988,7 +989,7 @@ mod tests {
988989
.unwrap(),
989990
reference: None,
990991
},
991-
directory: None,
992+
dir: None,
992993
uses: None,
993994
apply: None,
994995
});
@@ -1016,7 +1017,7 @@ mod tests {
10161017
url: Url::parse("git://github.com/rossmacarthur/sheldon-test").unwrap(),
10171018
reference: None,
10181019
},
1019-
directory: None,
1020+
dir: None,
10201021
uses: None,
10211022
apply: None,
10221023
});
@@ -1043,7 +1044,7 @@ mod tests {
10431044
url: Url::parse("https://github.com/rossmacarthur/sheldon-test").unwrap(),
10441045
reference: None,
10451046
},
1046-
directory: None,
1047+
dir: None,
10471048
uses: None,
10481049
apply: None,
10491050
});
@@ -1069,7 +1070,7 @@ mod tests {
10691070
url: Url::parse("ssh://git@github.com/rossmacarthur/sheldon-test").unwrap(),
10701071
reference: None,
10711072
},
1072-
directory: None,
1073+
dir: None,
10731074
uses: None,
10741075
apply: None,
10751076
});
@@ -1096,7 +1097,7 @@ mod tests {
10961097
let expected = Plugin::External(ExternalPlugin {
10971098
name: name.clone(),
10981099
source: Source::Remote { url: url.clone() },
1099-
directory: None,
1100+
dir: None,
11001101
uses: None,
11011102
apply: None,
11021103
});
@@ -1158,9 +1159,9 @@ mod tests {
11581159
let expected = Plugin::External(ExternalPlugin {
11591160
name: name.clone(),
11601161
source: Source::Local {
1161-
directory: "/home/temp".into(),
1162+
dir: "/home/temp".into(),
11621163
},
1163-
directory: None,
1164+
dir: None,
11641165
uses: None,
11651166
apply: None,
11661167
});

0 commit comments

Comments
 (0)