github.com/pquerna/agent@v2.1.8+incompatible/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/buildkite/agent/agent"
     8  	"github.com/buildkite/agent/clicommand"
     9  	"github.com/codegangsta/cli"
    10  )
    11  
    12  var AppHelpTemplate = `Usage:
    13  
    14    {{.Name}} <command> [arguments...]
    15  
    16  Available commands are:
    17  
    18    {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
    19    {{end}}
    20  Use "{{.Name}} <command> --help" for more information about a command.
    21  
    22  `
    23  
    24  var SubcommandHelpTemplate = `Usage:
    25  
    26    {{.Name}} {{if .Flags}}<command>{{end}} [arguments...]
    27  
    28  Available commands are:
    29  
    30     {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
    31     {{end}}{{if .Flags}}
    32  Options:
    33  
    34     {{range .Flags}}{{.}}
    35     {{end}}{{end}}
    36  `
    37  
    38  var CommandHelpTemplate = `{{.Description}}
    39  
    40  Options:
    41  
    42     {{range .Flags}}{{.}}
    43     {{end}}
    44  `
    45  
    46  func printVersion(c *cli.Context) {
    47  	fmt.Printf("%v version %v, build %v\n", c.App.Name, c.App.Version, agent.BuildVersion())
    48  }
    49  
    50  func main() {
    51  	cli.AppHelpTemplate = AppHelpTemplate
    52  	cli.CommandHelpTemplate = CommandHelpTemplate
    53  	cli.SubcommandHelpTemplate = SubcommandHelpTemplate
    54  	cli.VersionPrinter = printVersion
    55  
    56  	app := cli.NewApp()
    57  	app.Name = "buildkite-agent"
    58  	app.Version = agent.Version()
    59  	app.Commands = []cli.Command{
    60  		clicommand.AgentStartCommand,
    61  		{
    62  			Name:  "artifact",
    63  			Usage: "Upload/download artifacts from Buildkite jobs",
    64  			Subcommands: []cli.Command{
    65  				clicommand.ArtifactUploadCommand,
    66  				clicommand.ArtifactDownloadCommand,
    67  				clicommand.ArtifactShasumCommand,
    68  			},
    69  		},
    70  		{
    71  			Name:  "meta-data",
    72  			Usage: "Get/set data from Buildkite jobs",
    73  			Subcommands: []cli.Command{
    74  				clicommand.MetaDataSetCommand,
    75  				clicommand.MetaDataGetCommand,
    76  				clicommand.MetaDataExistsCommand,
    77  			},
    78  		},
    79  		{
    80  			Name:  "pipeline",
    81  			Usage: "Make changes to the pipeline of the currently running build",
    82  			Subcommands: []cli.Command{
    83  				clicommand.PipelineUploadCommand,
    84  			},
    85  		},
    86  	}
    87  
    88  	// When no sub command is used
    89  	app.Action = func(c *cli.Context) {
    90  		cli.ShowAppHelp(c)
    91  		os.Exit(1)
    92  	}
    93  
    94  	// When a sub command can't be found
    95  	app.CommandNotFound = func(c *cli.Context, command string) {
    96  		cli.ShowAppHelp(c)
    97  		os.Exit(1)
    98  	}
    99  
   100  	app.Run(os.Args)
   101  }