|
1 |
| -// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 1 | +// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved |
2 | 2 |
|
3 | 3 | package main
|
4 | 4 |
|
5 | 5 | import (
|
6 | 6 | "archive/zip"
|
7 |
| - "errors" |
| 7 | + "flag" |
8 | 8 | "fmt"
|
9 | 9 | "io/ioutil"
|
10 | 10 | "log"
|
11 | 11 | "os"
|
12 | 12 | "path/filepath"
|
13 |
| - |
14 |
| - "github.com/urfave/cli/v2" |
15 | 13 | )
|
16 | 14 |
|
17 |
| -func main() { |
18 |
| - app := &cli.App{ |
19 |
| - Name: "build-lambda-zip", |
20 |
| - Usage: "Put an executable and supplemental files into a zip file that works with AWS Lambda.", |
21 |
| - Flags: []cli.Flag{ |
22 |
| - &cli.StringFlag{ |
23 |
| - Name: "output", |
24 |
| - Aliases: []string{"o"}, |
25 |
| - Value: "", |
26 |
| - Usage: "output file path for the zip. Defaults to the first input file name.", |
27 |
| - }, |
28 |
| - }, |
29 |
| - Action: func(c *cli.Context) error { |
30 |
| - if !c.Args().Present() { |
31 |
| - return errors.New("no input provided") |
32 |
| - } |
33 |
| - |
34 |
| - inputExe := c.Args().First() |
35 |
| - outputZip := c.String("output") |
36 |
| - if outputZip == "" { |
37 |
| - outputZip = fmt.Sprintf("%s.zip", filepath.Base(inputExe)) |
38 |
| - } |
| 15 | +const usage = `build-lambda-zip - Puts an executable and supplemental files into a zip file that works with AWS Lambda. |
| 16 | +usage: |
| 17 | + build-lambda-zip [options] handler-exe [paths...] |
| 18 | +options: |
| 19 | + -o, --output output file path for the zip. (default: ${handler-exe}.zip) |
| 20 | + -h, --help prints usage |
| 21 | +` |
39 | 22 |
|
40 |
| - if err := compressExeAndArgs(outputZip, inputExe, c.Args().Tail()); err != nil { |
41 |
| - return fmt.Errorf("failed to compress file: %v", err) |
42 |
| - } |
43 |
| - log.Print("wrote " + outputZip) |
44 |
| - return nil |
45 |
| - }, |
| 23 | +func main() { |
| 24 | + var outputZip string |
| 25 | + flag.StringVar(&outputZip, "o", "", "") |
| 26 | + flag.StringVar(&outputZip, "output", "", "") |
| 27 | + flag.Usage = func() { |
| 28 | + fmt.Fprint(os.Stderr, usage) |
46 | 29 | }
|
47 |
| - |
48 |
| - if err := app.Run(os.Args); err != nil { |
49 |
| - fmt.Fprintf(os.Stderr, "%v\n", err) |
50 |
| - os.Exit(1) |
| 30 | + flag.Parse() |
| 31 | + if len(flag.Args()) == 0 { |
| 32 | + log.Fatal("no input provided") |
| 33 | + } |
| 34 | + inputExe := flag.Arg(0) |
| 35 | + if outputZip == "" { |
| 36 | + outputZip = fmt.Sprintf("%s.zip", filepath.Base(inputExe)) |
| 37 | + } |
| 38 | + if err := compressExeAndArgs(outputZip, inputExe, flag.Args()[1:]); err != nil { |
| 39 | + log.Fatalf("failed to compress file: %v", err) |
51 | 40 | }
|
| 41 | + log.Printf("wrote %s", outputZip) |
52 | 42 | }
|
53 | 43 |
|
54 | 44 | func writeExe(writer *zip.Writer, pathInZip string, data []byte) error {
|
|
0 commit comments