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