github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/fn/commands/images/bump.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/iron-io/functions/fn/common"
     6  	"github.com/urfave/cli"
     7  	"os"
     8  )
     9  
    10  var (
    11  	initialVersion = common.INITIAL_VERSION
    12  )
    13  
    14  func Bump() cli.Command {
    15  	cmd := bumpcmd{}
    16  	flags := append([]cli.Flag{}, cmd.flags()...)
    17  	return cli.Command{
    18  		Name:   "bump",
    19  		Usage:  "bump function version",
    20  		Flags:  flags,
    21  		Action: cmd.bump,
    22  	}
    23  }
    24  
    25  type bumpcmd struct {
    26  	verbose bool
    27  }
    28  
    29  func (b *bumpcmd) flags() []cli.Flag {
    30  	return []cli.Flag{
    31  		cli.BoolFlag{
    32  			Name:        "v",
    33  			Usage:       "verbose mode",
    34  			Destination: &b.verbose,
    35  		},
    36  	}
    37  }
    38  
    39  // bump will take the found valid function and bump its version
    40  func (b *bumpcmd) bump(c *cli.Context) error {
    41  	verbwriter := common.Verbwriter(b.verbose)
    42  
    43  	path, err := os.Getwd()
    44  	if err != nil {
    45  		return err
    46  	}
    47  	fn, err := common.FindFuncfile(path)
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	fmt.Fprintln(verbwriter, "bumping version for", fn)
    53  
    54  	funcfile, err := common.ParseFuncfile(fn)
    55  	if err != nil {
    56  		return err
    57  	}
    58  
    59  	err = funcfile.Bumpversion()
    60  	if err != nil {
    61  		return err
    62  	}
    63  
    64  	if err := common.StoreFuncfile(fn, funcfile); err != nil {
    65  		return err
    66  	}
    67  
    68  	fmt.Println("Bumped to version", funcfile.Version)
    69  	return nil
    70  }