forked from mmadfox/go-crx3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.go
49 lines (41 loc) · 1 KB
/
pack.go
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
package command
import (
"crypto/rsa"
"errors"
crx3 "github.com/zeqjone/go-crx"
"github.com/spf13/cobra"
)
type packOpts struct {
PrivateKey string
Outfile string
}
func (o packOpts) HasPem() bool {
return len(o.PrivateKey) > 0
}
func newPackCmd() *cobra.Command {
var opts packOpts
cmd := &cobra.Command{
Use: "pack [extension]",
Short: "Pack zip file or unzipped directory into a crx extension",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("infile is required")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
unpacked := args[0]
var pk *rsa.PrivateKey
if opts.HasPem() {
pk, err = crx3.LoadPrivateKey(opts.PrivateKey)
if err != nil {
return err
}
}
return crx3.Pack(unpacked, opts.Outfile, pk)
},
}
cmd.Flags().StringVarP(&opts.PrivateKey, "pem", "p", "", "load private key")
cmd.Flags().StringVarP(&opts.Outfile, "outfile", "o", "", "save to file")
return cmd
}