1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::path::PathBuf;
use structopt::StructOpt;
use text_block_macros::text_block;
#[derive(Debug, StructOpt)]
#[structopt(
name = "build-fs-tree",
long_about = text_block! {
"Create a filesystem tree from YAML"
""
"Source: https://github.com/KSXGitHub/build-fs-tree"
"Issues: https://github.com/KSXGitHub/build-fs-tree/issues"
"Donate: https://patreon.com/khai96_"
},
after_help = text_block! {
"EXAMPLES:"
" Create two text files in a new directory"
" $ echo '{ foo.txt: HELLO, bar.txt: WORLD }' | build-fs-tree create foo-and-bar"
""
" Create two text files in the current directory"
" $ echo '{ foo.txt: HELLO, bar.txt: WORLD }' | build-fs-tree populate ."
""
" Create a new filesystem tree from a YAML file"
" $ build-fs-tree create root < fs-tree.yaml"
""
" Populate the current directory with filesystem tree as described in a YAML file"
" $ build-fs-tree populate . < fs-tree.yaml"
},
)]
pub struct Args {
#[structopt(subcommand)]
pub command: Command,
}
#[derive(Debug, StructOpt)]
#[structopt(
rename_all = "kebab-case",
about = "Create a filesystem tree from YAML"
)]
pub enum Command {
#[structopt(
about = concat!(
"Read YAML from stdin and create a new filesystem tree at <TARGET>. ",
"Merged paths are not allowed",
),
after_help = text_block! {
"EXAMPLES:"
" Create two text files in a new directory"
" $ echo '{ foo.txt: HELLO, bar.txt: WORLD }' | build-fs-tree create foo-and-bar"
""
" Create a text file and its parent directories"
" $ echo '{ text-files: { foo.txt: HELLO } }' | build-fs-tree create files"
""
" Create a new filesystem tree from a YAML file"
" $ build-fs-tree create root < fs-tree.yaml"
},
)]
Create {
#[structopt(name = "TARGET")]
target: PathBuf,
},
#[structopt(
about = concat!(
"Read YAML from stdin and populate an existing filesystem tree at <TARGET>. ",
"Parent directories would be created if they are not already exist",
),
after_help = text_block! {
"EXAMPLES:"
" Create two text files in the current directory"
" $ echo '{ foo.txt: HELLO, bar.txt: WORLD }' | build-fs-tree populate ."
""
" Create a text file and its parent directories"
" $ echo '{ files/text-files/foo.txt: HELLO }' | build-fs-tree populate ."
""
" Populate the current directory with filesystem tree as described in a YAML file"
" $ build-fs-tree populate . < fs-tree.yaml"
},
)]
Populate {
#[structopt(name = "TARGET")]
target: PathBuf,
},
}