Skip to content

Commit

Permalink
fix capitalization in flag descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Aug 25, 2021
1 parent 2813224 commit 16be5a5
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cmd/mantil/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ var destroyCmd = &cobra.Command{
}

func init() {
destroyCmd.Flags().Bool("repo", false, "Delete Github repo and local code folder")
destroyCmd.Flags().Bool("repo", false, "delete Github repo and local code folder")
rootCmd.AddCommand(destroyCmd)
}
2 changes: 1 addition & 1 deletion cmd/mantil/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var generateApiCmd = &cobra.Command{
}

func init() {
generateApiCmd.Flags().StringSliceP("methods", "m", nil, "Specify additional function methods, if left empty only the default method will be created")
generateApiCmd.Flags().StringSliceP("methods", "m", nil, "additional function methods, if left empty only the Default method will be created")
generateCmd.AddCommand(generateApiCmd)
rootCmd.AddCommand(generateCmd)
}
6 changes: 3 additions & 3 deletions cmd/mantil/cmd/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ var invokeCmd = &cobra.Command{
}

func init() {
invokeCmd.Flags().StringP("data", "d", "", "Data for the request")
invokeCmd.Flags().BoolP("include", "i", false, "Include response headers in the output")
invokeCmd.Flags().BoolP("logs", "l", false, "Include lambda execution logs")
invokeCmd.Flags().StringP("data", "d", "", "data for the method invoke request")
invokeCmd.Flags().BoolP("include", "i", false, "include response headers in the output")
invokeCmd.Flags().BoolP("logs", "l", false, "show lambda execution logs")
rootCmd.AddCommand(invokeCmd)
}
10 changes: 5 additions & 5 deletions cmd/mantil/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var logsCmd = &cobra.Command{
Use: "logs",
Short: "Fetch logs for a specific function",
Short: "Fetch logs for a specific function/api",
Run: func(cmd *cobra.Command, args []string) {
function := cmd.Flag("function").Value.String()
start := cmd.Flag("start").Value.String()
Expand Down Expand Up @@ -46,9 +46,9 @@ var logsCmd = &cobra.Command{
}

func init() {
logsCmd.Flags().StringP("function", "f", "", "The function to fetch logs for")
logsCmd.Flags().String("filter", "", "The filter pattern to use. For more information, see Filter and Pattern Syntax (https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html)")
logsCmd.Flags().StringP("start", "s", "", "Time to start fetching logs from, logs before this time will be ignored. The default value is 3 hours ago")
logsCmd.Flags().BoolP("tail", "t", false, "Continue polling for new logs")
logsCmd.Flags().StringP("name", "n", "", "function/api name to fetch logs for")
logsCmd.Flags().String("filter-pattern", "p", "filter pattern to use see (https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html)")
logsCmd.Flags().StringP("since", "s", "", "from what time to begin displaying logs, default is 3 hours ago")
logsCmd.Flags().BoolP("follow", "f", false, "continuously poll for new logs")
rootCmd.AddCommand(logsCmd)
}
8 changes: 4 additions & 4 deletions cmd/mantil/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func init() {
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Config file (default is $HOME/.mantil.yaml)")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose log output")
rootCmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "Don't use color in log output")
//rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Config file (default is $HOME/.mantil.yaml)")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose log output")
rootCmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "don't use color in log output")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
//rootCmd.Flags().BoolP("toggle", "t", false, "help message for toggle")
}

// initConfig reads in config file and ENV variables if set.
Expand Down
23 changes: 20 additions & 3 deletions cmd/mantil/cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/mantil-io/mantil-cli/internal/commands/invoke"
"github.com/mantil-io/mantil-cli/internal/commands/watch"
"github.com/mantil-io/mantil-cli/internal/log"
"github.com/mantil-io/mantil.go/pkg/shell"
"github.com/spf13/cobra"
)

Expand All @@ -17,6 +18,7 @@ var watchCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
p, config, path, token := findProject(args)
method := cmd.Flag("method").Value.String()
test, _ := cmd.Flags().GetBool("test")
data := cmd.Flag("data").Value.String()

if method != "" && p.ApiURL == "" {
Expand All @@ -35,22 +37,37 @@ var watchCmd = &cobra.Command{
}

watch.Start(path, func() {
log.Info("changes detected - starting deploy")
log.Info("\nchanges detected - starting deploy")
if err := d.Deploy(); err != nil {
log.Fatal(err)
}
if !d.HasUpdates() {
return
}
if method != "" {
log.Info("invoking method %s", method)
if err := invoke.Endpoint(endpoint, data, false, true); err != nil {
log.Error(err)
}
}
if test {
log.Info("running tests")
err := shell.Exec(shell.ExecOptions{
Args: []string{"go", "test", "-v"},
WorkDir: path + "/test",
Logger: log.Info,
})
if err != nil {
log.Error(err)
}
}
})
},
}

func init() {
watchCmd.Flags().StringP("method", "m", "", "Method to invoke after deploying changes")
watchCmd.Flags().StringP("data", "d", "", "Data for the method request")
watchCmd.Flags().BoolP("test", "t", false, "run tests after deploying changes")
watchCmd.Flags().StringP("method", "m", "", "method to invoke after deploying changes")
watchCmd.Flags().StringP("data", "d", "", "data for the method invoke request")
rootCmd.AddCommand(watchCmd)
}
32 changes: 19 additions & 13 deletions internal/commands/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ const (
)

type DeployCmd struct {
aws *aws.AWS
project *mantil.Project
path string
token string
aws *aws.AWS
project *mantil.Project
path string
token string
functionUpdates []mantil.FunctionUpdate
}

func New(project *mantil.Project, awsClient *aws.AWS, path, token string) (*DeployCmd, error) {
Expand All @@ -42,25 +43,28 @@ func New(project *mantil.Project, awsClient *aws.AWS, path, token string) (*Depl
}

func (d *DeployCmd) Deploy() error {
functionUpdates, err := d.deploySync()
if err != nil {
if err := d.deploySync(); err != nil {
return err
}
if len(functionUpdates) == 0 {
if !d.HasUpdates() {
log.Info("no function changes - nothing to deploy")
return nil
}
if err = d.deployRequest(functionUpdates); err != nil {
if err := d.deployRequest(); err != nil {
return err
}
log.Notice("deploy successfully finished")
return nil
}

func (d *DeployCmd) deploySync() ([]mantil.FunctionUpdate, error) {
func (d *DeployCmd) HasUpdates() bool {
return len(d.functionUpdates) > 0
}

func (d *DeployCmd) deploySync() error {
localFuncs, err := d.localFunctions()
if err != nil {
return nil, err
return err
}

addedFuncs := d.processAddedFunctions(localFuncs)
Expand Down Expand Up @@ -93,8 +97,9 @@ func (d *DeployCmd) deploySync() ([]mantil.FunctionUpdate, error) {
Removed: true,
})
}
d.functionUpdates = functionUpdates

return functionUpdates, nil
return nil
}

func (d *DeployCmd) localFunctions() ([]string, error) {
Expand Down Expand Up @@ -177,6 +182,7 @@ func (d *DeployCmd) removedFunctions(localFuncs []string) []string {
func (d *DeployCmd) prepareFunctionsForDeploy() []mantil.Function {
funcsForDeploy := []mantil.Function{}
for i, f := range d.project.Functions {
log.Info("building function %s", f.Name)
funcDir := path.Join(d.path, FunctionsDir, f.Name)
isImage := d.isFunctionImage(funcDir)

Expand Down Expand Up @@ -246,7 +252,7 @@ func (d *DeployCmd) uploadBinaryToS3(key, binaryPath string) error {
return nil
}

func (d *DeployCmd) deployRequest(updates []mantil.FunctionUpdate) error {
func (d *DeployCmd) deployRequest() error {
type req struct {
ProjectName string
Token string
Expand All @@ -255,7 +261,7 @@ func (d *DeployCmd) deployRequest(updates []mantil.FunctionUpdate) error {
r := &req{
ProjectName: d.project.Name,
Token: d.token,
FunctionUpdates: updates,
FunctionUpdates: d.functionUpdates,
}
return commands.BackendRequest("deploy", r, nil)
}
2 changes: 1 addition & 1 deletion internal/commands/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func generateApi(projectPath, functionName string, methods []string) error {
}

func generateApiDefault(projectPath, functionName string) error {
defaultFile := path.Join(projectPath, "api", functionName, "default.go")
defaultFile := path.Join(projectPath, "api", functionName, functionName+".go")
if fileExists(defaultFile) {
log.Debug("default method already exists, skipping...")
return nil
Expand Down
8 changes: 3 additions & 5 deletions internal/generate/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ type {{ .Name | title }} struct{}
type DefaultRequest struct{}
type DefaultResponse struct{}
func ({{ .Name | first | toLower }} *{{ .Name | title }}) Init(ctx context.Context) {}
func New() *{{ .Name | title }} {
return &{{ .Name | title }}{}
}
func ({{ .Name | first | toLower }} *{{ .Name | title }}) Default(ctx context.Context, req *DefaultRequest) (*DefaultResponse, error) {
panic("not implemented")
}
func New() *{{ .Name | title }} {
return &{{ .Name | title }}{}
}
`

var APIMethodTemplate = `
Expand Down

0 comments on commit 16be5a5

Please sign in to comment.