Skip to content

Commit

Permalink
cmd/build-lambda-zip: remove dependency on github.com/urfave/cli/v2 (#…
Browse files Browse the repository at this point in the history
…439)

* main.go fix copyright

* cmd/build-lambda-zip: remove dependency on github.com/urfave/cli/v2
  • Loading branch information
bmoffatt authored Apr 13, 2022
1 parent 138d021 commit a0b8eda
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 50 deletions.
62 changes: 26 additions & 36 deletions cmd/build-lambda-zip/main.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,44 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved

package main

import (
"archive/zip"
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/urfave/cli/v2"
)

func main() {
app := &cli.App{
Name: "build-lambda-zip",
Usage: "Put an executable and supplemental files into a zip file that works with AWS Lambda.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Value: "",
Usage: "output file path for the zip. Defaults to the first input file name.",
},
},
Action: func(c *cli.Context) error {
if !c.Args().Present() {
return errors.New("no input provided")
}

inputExe := c.Args().First()
outputZip := c.String("output")
if outputZip == "" {
outputZip = fmt.Sprintf("%s.zip", filepath.Base(inputExe))
}
const usage = `build-lambda-zip - Puts an executable and supplemental files into a zip file that works with AWS Lambda.
usage:
build-lambda-zip [options] handler-exe [paths...]
options:
-o, --output output file path for the zip. (default: ${handler-exe}.zip)
-h, --help prints usage
`

if err := compressExeAndArgs(outputZip, inputExe, c.Args().Tail()); err != nil {
return fmt.Errorf("failed to compress file: %v", err)
}
log.Print("wrote " + outputZip)
return nil
},
func main() {
var outputZip string
flag.StringVar(&outputZip, "o", "", "")
flag.StringVar(&outputZip, "output", "", "")
flag.Usage = func() {
fmt.Fprint(os.Stderr, usage)
}

if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
flag.Parse()
if len(flag.Args()) == 0 {
log.Fatal("no input provided")
}
inputExe := flag.Arg(0)
if outputZip == "" {
outputZip = fmt.Sprintf("%s.zip", filepath.Base(inputExe))
}
if err := compressExeAndArgs(outputZip, inputExe, flag.Args()[1:]); err != nil {
log.Fatalf("failed to compress file: %v", err)
}
log.Printf("wrote %s", outputZip)
}

func writeExe(writer *zip.Writer, pathInZip string, data []byte) error {
Expand Down
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ module github.com/aws/aws-lambda-go

go 1.18

require (
github.com/stretchr/testify v1.6.1
github.com/urfave/cli/v2 v2.4.0
)
require github.com/stretchr/testify v1.6.1

require (
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.4.0 h1:m2pxjjDFgDxSPtO8WSdbndj17Wu2y8vOT86wE/tjr+I=
github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5LbaEYPg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit a0b8eda

Please sign in to comment.