github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/commands.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hashicorp/nomad/command"
     7  	"github.com/hashicorp/nomad/command/agent"
     8  	"github.com/mitchellh/cli"
     9  )
    10  
    11  // Commands returns the mapping of CLI commands for Nomad. The meta
    12  // parameter lets you set meta options for all commands.
    13  func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
    14  	if metaPtr == nil {
    15  		metaPtr = new(command.Meta)
    16  	}
    17  
    18  	meta := *metaPtr
    19  	if meta.Ui == nil {
    20  		meta.Ui = &cli.BasicUi{
    21  			Reader:      os.Stdin,
    22  			Writer:      os.Stdout,
    23  			ErrorWriter: os.Stderr,
    24  		}
    25  	}
    26  
    27  	return map[string]cli.CommandFactory{
    28  		"alloc-status": func() (cli.Command, error) {
    29  			return &command.AllocStatusCommand{
    30  				Meta: meta,
    31  			}, nil
    32  		},
    33  		"agent": func() (cli.Command, error) {
    34  			return &agent.Command{
    35  				Revision:          GitCommit,
    36  				Version:           Version,
    37  				VersionPrerelease: VersionPrerelease,
    38  				Ui:                meta.Ui,
    39  				ShutdownCh:        make(chan struct{}),
    40  			}, nil
    41  		},
    42  		"agent-info": func() (cli.Command, error) {
    43  			return &command.AgentInfoCommand{
    44  				Meta: meta,
    45  			}, nil
    46  		},
    47  		"check": func() (cli.Command, error) {
    48  			return &command.AgentCheckCommand{
    49  				Meta: meta,
    50  			}, nil
    51  		},
    52  		"client-config": func() (cli.Command, error) {
    53  			return &command.ClientConfigCommand{
    54  				Meta: meta,
    55  			}, nil
    56  		},
    57  		"eval-status": func() (cli.Command, error) {
    58  			return &command.EvalStatusCommand{
    59  				Meta: meta,
    60  			}, nil
    61  		},
    62  		"executor": func() (cli.Command, error) {
    63  			return &command.ExecutorPluginCommand{
    64  				Meta: meta,
    65  			}, nil
    66  		},
    67  		"fs": func() (cli.Command, error) {
    68  			return &command.FSCommand{
    69  				Meta: meta,
    70  			}, nil
    71  		},
    72  		"init": func() (cli.Command, error) {
    73  			return &command.InitCommand{
    74  				Meta: meta,
    75  			}, nil
    76  		},
    77  		"inspect": func() (cli.Command, error) {
    78  			return &command.InspectCommand{
    79  				Meta: meta,
    80  			}, nil
    81  		},
    82  		"logs": func() (cli.Command, error) {
    83  			return &command.LogsCommand{
    84  				Meta: meta,
    85  			}, nil
    86  		},
    87  		"node-drain": func() (cli.Command, error) {
    88  			return &command.NodeDrainCommand{
    89  				Meta: meta,
    90  			}, nil
    91  		},
    92  		"node-status": func() (cli.Command, error) {
    93  			return &command.NodeStatusCommand{
    94  				Meta: meta,
    95  			}, nil
    96  		},
    97  
    98  		"plan": func() (cli.Command, error) {
    99  			return &command.PlanCommand{
   100  				Meta: meta,
   101  			}, nil
   102  		},
   103  
   104  		"run": func() (cli.Command, error) {
   105  			return &command.RunCommand{
   106  				Meta: meta,
   107  			}, nil
   108  		},
   109  		"syslog": func() (cli.Command, error) {
   110  			return &command.SyslogPluginCommand{
   111  				Meta: meta,
   112  			}, nil
   113  		},
   114  		"server-force-leave": func() (cli.Command, error) {
   115  			return &command.ServerForceLeaveCommand{
   116  				Meta: meta,
   117  			}, nil
   118  		},
   119  		"server-join": func() (cli.Command, error) {
   120  			return &command.ServerJoinCommand{
   121  				Meta: meta,
   122  			}, nil
   123  		},
   124  		"server-members": func() (cli.Command, error) {
   125  			return &command.ServerMembersCommand{
   126  				Meta: meta,
   127  			}, nil
   128  		},
   129  		"status": func() (cli.Command, error) {
   130  			return &command.StatusCommand{
   131  				Meta: meta,
   132  			}, nil
   133  		},
   134  		"stop": func() (cli.Command, error) {
   135  			return &command.StopCommand{
   136  				Meta: meta,
   137  			}, nil
   138  		},
   139  		"validate": func() (cli.Command, error) {
   140  			return &command.ValidateCommand{
   141  				Meta: meta,
   142  			}, nil
   143  		},
   144  		"version": func() (cli.Command, error) {
   145  			ver := Version
   146  			rel := VersionPrerelease
   147  			if GitDescribe != "" {
   148  				ver = GitDescribe
   149  				// Trim off a leading 'v', we append it anyways.
   150  				if ver[0] == 'v' {
   151  					ver = ver[1:]
   152  				}
   153  			}
   154  			if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
   155  				rel = "dev"
   156  			}
   157  
   158  			return &command.VersionCommand{
   159  				Revision:          GitCommit,
   160  				Version:           ver,
   161  				VersionPrerelease: rel,
   162  				Ui:                meta.Ui,
   163  			}, nil
   164  		},
   165  	}
   166  }