-
Notifications
You must be signed in to change notification settings - Fork 0
/
label.ts
49 lines (42 loc) · 1.49 KB
/
label.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
import { IDockerCommand } from '../stage';
/**
* @see https://docs.docker.com/engine/reference/builder/#label
*/
export class Label implements IDockerCommand {
public labels : Map<string, string>;
constructor(name: string, value: string);
constructor(labels: [ string, string ][]);
constructor(labels: Map<string, string>);
constructor(nameOrLabels : string|[ string, string ][]|Map<string, string>, value?: string) {
if(typeof nameOrLabels === 'string') {
this.labels = new Map([
[nameOrLabels, value!]
]);
} else if (Array.isArray(nameOrLabels)) {
this.labels = new Map(nameOrLabels);
} else {
this.labels = new Map(nameOrLabels.entries());
}
}
toDockerCommand() {
if(0 === this.labels.size) {
return '';
}
let cmd = `LABEL `;
let first = true;
for(const [ name, value ] of this.labels) {
if(!first) {
cmd += ' \\\n ';
}
cmd += `${JSON.stringify(name)}=${JSON.stringify(value)}`;
first = false;
}
return cmd;
}
}
export function label(name: string, value: string) : Label;
export function label(labels: [ string, string ][]) : Label;
export function label(labels: Map<string, string>) : Label;
export function label(nameOrLabels : string|[ string, string ][]|Map<string, string>, value?: string) {
return new Label(nameOrLabels as any, value as any);
}