github.com/gdavison/packer@v0.10.1/commands.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"os/signal"
     6  
     7  	"github.com/mitchellh/cli"
     8  	"github.com/mitchellh/packer/command"
     9  	"github.com/mitchellh/packer/version"
    10  )
    11  
    12  // Commands is the mapping of all the available Terraform commands.
    13  var Commands map[string]cli.CommandFactory
    14  
    15  // CommandMeta is the Meta to use for the commands. This must be written
    16  // before the CLI is started.
    17  var CommandMeta *command.Meta
    18  
    19  const ErrorPrefix = "e:"
    20  const OutputPrefix = "o:"
    21  
    22  func init() {
    23  	Commands = map[string]cli.CommandFactory{
    24  		"build": func() (cli.Command, error) {
    25  			return &command.BuildCommand{
    26  				Meta: *CommandMeta,
    27  			}, nil
    28  		},
    29  
    30  		"fix": func() (cli.Command, error) {
    31  			return &command.FixCommand{
    32  				Meta: *CommandMeta,
    33  			}, nil
    34  		},
    35  
    36  		"inspect": func() (cli.Command, error) {
    37  			return &command.InspectCommand{
    38  				Meta: *CommandMeta,
    39  			}, nil
    40  		},
    41  
    42  		"push": func() (cli.Command, error) {
    43  			return &command.PushCommand{
    44  				Meta: *CommandMeta,
    45  			}, nil
    46  		},
    47  
    48  		"validate": func() (cli.Command, error) {
    49  			return &command.ValidateCommand{
    50  				Meta: *CommandMeta,
    51  			}, nil
    52  		},
    53  
    54  		"version": func() (cli.Command, error) {
    55  			return &command.VersionCommand{
    56  				Meta:              *CommandMeta,
    57  				Revision:          version.GitCommit,
    58  				Version:           version.Version,
    59  				VersionPrerelease: version.VersionPrerelease,
    60  				CheckFunc:         commandVersionCheck,
    61  			}, nil
    62  		},
    63  
    64  		"plugin": func() (cli.Command, error) {
    65  			return &command.PluginCommand{
    66  				Meta: *CommandMeta,
    67  			}, nil
    68  		},
    69  	}
    70  }
    71  
    72  // makeShutdownCh creates an interrupt listener and returns a channel.
    73  // A message will be sent on the channel for every interrupt received.
    74  func makeShutdownCh() <-chan struct{} {
    75  	resultCh := make(chan struct{})
    76  
    77  	signalCh := make(chan os.Signal, 4)
    78  	signal.Notify(signalCh, os.Interrupt)
    79  	go func() {
    80  		for {
    81  			<-signalCh
    82  			resultCh <- struct{}{}
    83  		}
    84  	}()
    85  
    86  	return resultCh
    87  }