@@ -81,49 +81,51 @@ func archiveBytesFromReader(r io.Reader, manifestBytes, bridgeCfgBytes []byte) [
81
81
// Flags for the pack subcommand.
82
82
type packFlags struct {
83
83
// The flags proper:
84
- pkgDef , imageFile , image , outFilename , altAppKey * string
84
+ pkgDef , imageFile , image , outFilename , altAppKey string
85
85
86
86
// The two logical parts of pkgDef:
87
87
pkgDefFile , pkgDefVar string
88
88
}
89
89
90
- func registerPackFlags () * packFlags {
91
- return & packFlags {
92
- pkgDef : flag .String (
93
- "pkg-def" ,
94
- "sandstorm-pkgdef.capnp:pkgdef" ,
95
- "The location from which to read the package definition, of the form\n " +
96
- "<def-file>:<name>. <def-file> is the name of the file to look in,\n " +
97
- "and <name> is the name of the constant defining the package\n " +
98
- "definition." ,
99
- ),
100
- imageFile : flag .String ("imagefile" , "" ,
101
- "File containing Docker image to convert (output of \" docker save\" )" ,
102
- ),
103
- image : flag .String ("image" , "" ,
104
- "Name of the image to convert (fetched from the running docker daemon)." ,
105
- ),
106
- outFilename : flag .String ("out" , "" ,
107
- "File name of the resulting spk (default inferred from package metadata)" ,
108
- ),
109
- altAppKey : flag .String ("appkey" , "" ,
110
- "Sign the package with the specified app key, instead of the one\n " +
111
- "defined in the package definition. This can be useful if e.g.\n " +
112
- "you do not have access to the key with which the final app is\n " +
113
- "published." ),
114
- }
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 ,
100
+ "imagefile" , "" ,
101
+ "File containing Docker image to convert (output of \" docker save\" )" ,
102
+ )
103
+ flag .StringVar (& p .image ,
104
+ "image" , "" ,
105
+ "Name of the image to convert (fetched from the running docker daemon)." ,
106
+ )
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." )
115
117
}
116
118
117
119
func (p * packFlags ) Parse () {
118
120
flag .Parse ()
119
- if * p .imageFile == "" && * p .image == "" {
121
+ if p .imageFile == "" && p .image == "" {
120
122
usageErr ("Missing option: -image or -imagefile" )
121
123
}
122
- if * p .imageFile != "" && * p .image != "" {
124
+ if p .imageFile != "" && p .image != "" {
123
125
usageErr ("Only one of -image or -imagefile may be specified." )
124
126
}
125
127
126
- pkgDefParts := strings .SplitN (* p .pkgDef , ":" , 2 )
128
+ pkgDefParts := strings .SplitN (p .pkgDef , ":" , 2 )
127
129
if len (pkgDefParts ) != 2 {
128
130
usageErr ("-pkg-def's argument must be of the form <def-file>:<name>" )
129
131
}
@@ -132,17 +134,18 @@ func (p *packFlags) Parse() {
132
134
}
133
135
134
136
func packCmd () {
135
- pFlags := registerPackFlags ()
137
+ pFlags := & packFlags {}
138
+ pFlags .Register ()
136
139
pFlags .Parse ()
137
140
138
141
metadata := getPkgMetadata (pFlags .pkgDefFile , pFlags .pkgDefVar )
139
142
140
143
keyring , err := loadKeyring (* keyringPath )
141
144
chkfatal ("loading the sandstorm keyring" , err )
142
145
143
- if * pFlags .altAppKey != "" {
146
+ if pFlags .altAppKey != "" {
144
147
// The user has requested we use a different key.
145
- metadata .appId = * pFlags .altAppKey
148
+ metadata .appId = pFlags .altAppKey
146
149
}
147
150
148
151
appPubKey , err := SandstormBase32Encoding .DecodeString (metadata .appId )
@@ -152,22 +155,22 @@ func packCmd() {
152
155
chkfatal ("Fetching the app private key" , err )
153
156
154
157
var archiveBytes []byte
155
- if * pFlags .imageFile != "" {
156
- archiveBytes = archiveBytesFromFilename (* pFlags .imageFile , metadata .manifest , metadata .bridgeCfg )
157
- } else if * pFlags .image != "" {
158
- archiveBytes = archiveBytesFromDocker (* pFlags .image , metadata .manifest , metadata .bridgeCfg )
158
+ if pFlags .imageFile != "" {
159
+ archiveBytes = archiveBytesFromFilename (pFlags .imageFile , metadata .manifest , metadata .bridgeCfg )
160
+ } else if pFlags .image != "" {
161
+ archiveBytes = archiveBytesFromDocker (pFlags .image , metadata .manifest , metadata .bridgeCfg )
159
162
} else {
160
163
// pFlags.Parse() should have ruled this out.
161
164
panic ("impossible" )
162
165
}
163
166
sigBytes := signatureMessage (appKeyFile , archiveBytes )
164
167
165
- if * pFlags .outFilename == "" {
168
+ if pFlags .outFilename == "" {
166
169
// infer output file from app metadata:
167
- * pFlags .outFilename = metadata .name + "-" + metadata .version + ".spk"
170
+ pFlags .outFilename = metadata .name + "-" + metadata .version + ".spk"
168
171
}
169
172
170
- outFile , err := os .Create (* pFlags .outFilename )
173
+ outFile , err := os .Create (pFlags .outFilename )
171
174
chkfatal ("opening output file" , err )
172
175
defer outFile .Close ()
173
176
0 commit comments