-
Notifications
You must be signed in to change notification settings - Fork 31
/
CommandLineArgumentSettingsLoader.ts
86 lines (83 loc) · 2.2 KB
/
CommandLineArgumentSettingsLoader.ts
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
import { ConfluenceSettings } from "../Settings";
import { SettingsLoader } from "./SettingsLoader";
import yargs from "yargs";
export class CommandLineArgumentSettingsLoader extends SettingsLoader {
getValue<T extends keyof ConfluenceSettings>(
propertyKey: T,
envVar: string
): Partial<ConfluenceSettings> {
const value = process.env[envVar];
return value ? { [propertyKey]: value } : {};
}
loadPartial(): Partial<ConfluenceSettings> {
const options = yargs(process.argv)
.usage("Usage: $0 [options]")
.option("baseUrl", {
alias: "b",
describe: "Confluence base URL",
type: "string",
demandOption: false,
})
.option("parentId", {
alias: "p",
describe: "Confluence parent ID",
type: "string",
demandOption: false,
})
.option("userName", {
alias: "u",
describe: "Atlassian user name",
type: "string",
demandOption: false,
})
.option("apiToken", {
describe: "Atlassian API token",
type: "string",
demandOption: false,
})
.option("enableFolder", {
alias: "f",
describe: "Folder enable to publish",
type: "string",
demandOption: false,
})
.option("contentRoot", {
alias: "cr",
describe:
"Root to search for files to publish. All files must be part of this directory.",
type: "string",
demandOption: false,
})
.option("firstHeaderPageTitle", {
alias: "fh",
describe:
"Replace page title with first header element when 'connie-title' isn't specified.",
type: "boolean",
demandOption: false,
})
.parseSync();
return {
...(options.baseUrl
? { confluenceBaseUrl: options.baseUrl }
: undefined),
...(options.parentId
? { confluenceParentId: options.parentId }
: undefined),
...(options.userName
? { atlassianUserName: options.userName }
: undefined),
...(options.apiToken
? { atlassianApiToken: options.apiToken }
: undefined),
...(options.enableFolder
? { folderToPublish: options.enableFolder }
: undefined),
...(options.contentRoot
? { contentRoot: options.contentRoot }
: undefined),
...(options.firstHeaderPageTitle
? { firstHeadingPageTitle: options.firstHeaderPageTitle }
: undefined),
};
}
}