Skip to content

Commit 332150c

Browse files
committed
Factor some common flags out from pack flags.
These will also be used by build, which packs the result.
1 parent 8dae142 commit 332150c

File tree

2 files changed

+61
-37
lines changed

2 files changed

+61
-37
lines changed

build.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"strings"
6+
)
7+
8+
type buildFlags struct {
9+
// The flags proper:
10+
pkgDef, outFilename, altAppKey string
11+
12+
// The two logical parts of pkgDef:
13+
pkgDefFile, pkgDefVar string
14+
}
15+
16+
func (f *buildFlags) Register() {
17+
flag.StringVar(&f.pkgDef,
18+
"pkg-def",
19+
"sandstorm-pkgdef.capnp:pkgdef",
20+
"The location from which to read the package definition, of the form\n"+
21+
"<def-file>:<name>. <def-file> is the name of the file to look in,\n"+
22+
"and <name> is the name of the constant defining the package\n"+
23+
"definition.",
24+
)
25+
flag.StringVar(&f.outFilename,
26+
"out", "",
27+
"File name of the resulting spk (default inferred from package metadata)",
28+
)
29+
flag.StringVar(&f.altAppKey,
30+
"appkey", "",
31+
"Sign the package with the specified app key, instead of the one\n"+
32+
"defined in the package definition. This can be useful if e.g.\n"+
33+
"you do not have access to the key with which the final app is\n"+
34+
"published.")
35+
}
36+
37+
func (f *buildFlags) Parse() {
38+
flag.Parse()
39+
pkgDefParts := strings.SplitN(f.pkgDef, ":", 2)
40+
if len(pkgDefParts) != 2 {
41+
usageErr("-pkg-def's argument must be of the form <def-file>:<name>")
42+
}
43+
f.pkgDefFile = pkgDefParts[0]
44+
f.pkgDefVar = pkgDefParts[1]
45+
}
46+
47+
func buildCmd() {
48+
49+
}

pack.go

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"io"
77
"os"
88
"os/exec"
9-
"strings"
109

1110
"github.com/ulikunitz/xz"
1211
"zenhack.net/go/sandstorm/capnp/spk"
@@ -80,57 +79,33 @@ func archiveBytesFromReader(r io.Reader, manifestBytes, bridgeCfgBytes []byte) [
8079

8180
// Flags for the pack subcommand.
8281
type packFlags struct {
83-
// The flags proper:
84-
pkgDef, imageFile, image, outFilename, altAppKey string
82+
// flags shared with the build command:
83+
buildFlags
8584

86-
// The two logical parts of pkgDef:
87-
pkgDefFile, pkgDefVar string
85+
// other flags:
86+
imageFile, image string
8887
}
8988

90-
func (p *packFlags) Register() {
91-
flag.StringVar(&p.pkgDef,
92-
"pkg-def",
93-
"sandstorm-pkgdef.capnp:pkgdef",
94-
"The location from which to read the package definition, of the form\n"+
95-
"<def-file>:<name>. <def-file> is the name of the file to look in,\n"+
96-
"and <name> is the name of the constant defining the package\n"+
97-
"definition.",
98-
)
99-
flag.StringVar(&p.imageFile,
89+
func (f *packFlags) Register() {
90+
f.buildFlags.Register()
91+
flag.StringVar(&f.imageFile,
10092
"imagefile", "",
10193
"File containing Docker image to convert (output of \"docker save\")",
10294
)
103-
flag.StringVar(&p.image,
95+
flag.StringVar(&f.image,
10496
"image", "",
10597
"Name of the image to convert (fetched from the running docker daemon).",
10698
)
107-
flag.StringVar(&p.outFilename,
108-
"out", "",
109-
"File name of the resulting spk (default inferred from package metadata)",
110-
)
111-
flag.StringVar(&p.altAppKey,
112-
"appkey", "",
113-
"Sign the package with the specified app key, instead of the one\n"+
114-
"defined in the package definition. This can be useful if e.g.\n"+
115-
"you do not have access to the key with which the final app is\n"+
116-
"published.")
11799
}
118100

119-
func (p *packFlags) Parse() {
120-
flag.Parse()
121-
if p.imageFile == "" && p.image == "" {
101+
func (f *packFlags) Parse() {
102+
f.buildFlags.Parse()
103+
if f.imageFile == "" && f.image == "" {
122104
usageErr("Missing option: -image or -imagefile")
123105
}
124-
if p.imageFile != "" && p.image != "" {
106+
if f.imageFile != "" && f.image != "" {
125107
usageErr("Only one of -image or -imagefile may be specified.")
126108
}
127-
128-
pkgDefParts := strings.SplitN(p.pkgDef, ":", 2)
129-
if len(pkgDefParts) != 2 {
130-
usageErr("-pkg-def's argument must be of the form <def-file>:<name>")
131-
}
132-
p.pkgDefFile = pkgDefParts[0]
133-
p.pkgDefVar = pkgDefParts[1]
134109
}
135110

136111
func packCmd() {

0 commit comments

Comments
 (0)