-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintro-effect.ts
More file actions
92 lines (90 loc) · 2.14 KB
/
intro-effect.ts
File metadata and controls
92 lines (90 loc) · 2.14 KB
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
import { Schema } from 'effect'
import { Command } from '../src/_entrypoints/_.js'
import { EffectSchema } from '../src/_entrypoints/extensions.js'
const args = await Command.create()
.use(EffectSchema)
.parameter(
`filePath`,
Schema.String.pipe(
Schema.annotations({ description: `Path to the file to convert.` }),
),
)
.parameter(
`to`,
Schema.Literal(`json`, `yaml`, `toml`).pipe(
Schema.annotations({ description: `Format to convert to.` }),
),
)
.parameter(
`from`,
Schema.UndefinedOr(Schema.Literal(`json`, `yaml`, `toml`)).pipe(
Schema.annotations({ description: `Source format (auto-detected if omitted).` }),
),
)
.parameter(
`output o`,
Schema.UndefinedOr(Schema.String).pipe(
Schema.annotations({ description: `Output file path (prints to stdout if omitted).` }),
),
)
.parameter(
`encoding`,
Schema.UndefinedOr(Schema.Literal(`utf8`, `utf16`, `ascii`)).pipe(
Schema.annotations({ description: `File encoding to use.` }),
),
)
.parameter(
`verbose v`,
Schema.transform(
Schema.UndefinedOr(Schema.Boolean),
Schema.Boolean,
{
strict: true,
decode: (value) => value ?? false,
encode: (value) => value,
},
).pipe(
Schema.annotations({
description: `Log detailed progress as conversion executes.`,
default: false,
}),
),
)
.parameter(
`move m`,
Schema.transform(
Schema.UndefinedOr(Schema.Boolean),
Schema.Boolean,
{
strict: true,
decode: (value) => value ?? false,
encode: (value) => value,
},
).pipe(
Schema.annotations({
description: `Delete the original file after it has been converted.`,
default: false,
}),
),
)
.settings({
prompt: {
// TODO allow making parameter level opt-in or opt-out
// default: false,
when: [
{
result: `rejected`,
error: `ErrorMissingArgument`,
},
{ result: `omitted` },
],
},
})
.parse()
args.filePath
args.from
args.to
args.output
args.encoding
args.verbose
args.move