-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathcli-config.ts
135 lines (127 loc) · 3.39 KB
/
cli-config.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { RecursivePartial } from '@theia/core/lib/common/types';
import { Daemon } from '../common/protocol/config-service';
export const CLI_CONFIG = 'arduino-cli.yaml';
export interface BoardManager {
readonly additional_urls: Array<string>;
}
export namespace BoardManager {
export function sameAs(
left: RecursivePartial<BoardManager> | undefined,
right: RecursivePartial<BoardManager> | undefined
): boolean {
const leftOrDefault = left || {};
const rightOrDefault = right || {};
const leftUrls = Array.from(new Set(leftOrDefault.additional_urls || []));
const rightUrls = Array.from(new Set(rightOrDefault.additional_urls || []));
if (leftUrls.length !== rightUrls.length) {
return false;
}
return leftUrls.every((url) => rightUrls.indexOf(url) !== -1);
}
}
export interface Directories {
readonly data: string;
readonly downloads: string;
readonly user: string;
}
export namespace Directories {
export function is(
directories: RecursivePartial<Directories> | undefined
): directories is Directories {
return (
!!directories &&
!!directories.data &&
!!directories.downloads &&
!!directories.user
);
}
export function sameAs(
left: RecursivePartial<Directories> | undefined,
right: RecursivePartial<Directories> | undefined
): boolean {
if (left === undefined) {
return right === undefined;
}
if (right === undefined) {
return left === undefined;
}
return (
left.data === right.data &&
left.downloads === right.downloads &&
left.user === right.user
);
}
}
export interface Logging {
file: string;
format: Logging.Format;
level: Logging.Level;
}
export namespace Logging {
export type Format = 'text' | 'json';
export type Level =
| 'trace'
| 'debug'
| 'info'
| 'warning'
| 'error'
| 'fatal'
| 'panic';
export function sameAs(
left: RecursivePartial<Logging> | undefined,
right: RecursivePartial<Logging> | undefined
): boolean {
if (left === undefined) {
return right === undefined;
}
if (right === undefined) {
return left === undefined;
}
if (left.file !== right.file) {
return false;
}
if (left.format !== right.format) {
return false;
}
if (left.level !== right.level) {
return false;
}
return true;
}
}
export interface Network {
proxy?: string;
}
// Arduino CLI config scheme
export interface CliConfig {
locale?: string;
board_manager?: RecursivePartial<BoardManager>;
directories?: RecursivePartial<Directories>;
logging?: RecursivePartial<Logging>;
network?: RecursivePartial<Network>;
}
// Bare minimum required CLI config.
export interface DefaultCliConfig extends CliConfig {
directories: Directories;
daemon: Daemon;
}
export namespace DefaultCliConfig {
export function is(
config: RecursivePartial<DefaultCliConfig> | undefined
): config is DefaultCliConfig {
return (
!!config && Directories.is(config.directories) && Daemon.is(config.daemon)
);
}
export function sameAs(
left: DefaultCliConfig,
right: DefaultCliConfig
): boolean {
return (
Directories.sameAs(left.directories, right.directories) &&
Daemon.sameAs(left.daemon, right.daemon) &&
BoardManager.sameAs(left.board_manager, right.board_manager) &&
Logging.sameAs(left.logging, right.logging)
);
}
}