github.com/ranjib/nomad@v0.1.1-0.20160225204057-97751b02f70b/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  			Writer:      os.Stdout,
    22  			ErrorWriter: os.Stderr,
    23  		}
    24  	}
    25  
    26  	return map[string]cli.CommandFactory{
    27  		"alloc-status": func() (cli.Command, error) {
    28  			return &command.AllocStatusCommand{
    29  				Meta: meta,
    30  			}, nil
    31  		},
    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  
    43  		"agent-info": func() (cli.Command, error) {
    44  			return &command.AgentInfoCommand{
    45  				Meta: meta,
    46  			}, nil
    47  		},
    48  
    49  		"client-config": func() (cli.Command, error) {
    50  			return &command.ClientConfigCommand{
    51  				Meta: meta,
    52  			}, nil
    53  		},
    54  
    55  		"eval-monitor": func() (cli.Command, error) {
    56  			return &command.EvalMonitorCommand{
    57  				Meta: meta,
    58  			}, nil
    59  		},
    60  		"executor": func() (cli.Command, error) {
    61  			return &command.ExecutorPluginCommand{
    62  				Meta: meta,
    63  			}, nil
    64  		},
    65  		"fs": func() (cli.Command, error) {
    66  			return &command.FSCommand{
    67  				Meta: meta,
    68  			}, nil
    69  		},
    70  		"fs ls": func() (cli.Command, error) {
    71  			return &command.FSListCommand{
    72  				Meta: meta,
    73  			}, nil
    74  		},
    75  		"fs stat": func() (cli.Command, error) {
    76  			return &command.FSStatCommand{
    77  				Meta: meta,
    78  			}, nil
    79  		},
    80  		"fs cat": func() (cli.Command, error) {
    81  			return &command.FSCatCommand{
    82  				Meta: meta,
    83  			}, nil
    84  		},
    85  		"init": func() (cli.Command, error) {
    86  			return &command.InitCommand{
    87  				Meta: meta,
    88  			}, nil
    89  		},
    90  
    91  		"node-drain": func() (cli.Command, error) {
    92  			return &command.NodeDrainCommand{
    93  				Meta: meta,
    94  			}, nil
    95  		},
    96  
    97  		"node-status": func() (cli.Command, error) {
    98  			return &command.NodeStatusCommand{
    99  				Meta: meta,
   100  			}, nil
   101  		},
   102  
   103  		"run": func() (cli.Command, error) {
   104  			return &command.RunCommand{
   105  				Meta: meta,
   106  			}, nil
   107  		},
   108  		"syslog": func() (cli.Command, error) {
   109  			return &command.SyslogPluginCommand{
   110  				Meta: meta,
   111  			}, nil
   112  		},
   113  		"server-force-leave": func() (cli.Command, error) {
   114  			return &command.ServerForceLeaveCommand{
   115  				Meta: meta,
   116  			}, nil
   117  		},
   118  
   119  		"server-join": func() (cli.Command, error) {
   120  			return &command.ServerJoinCommand{
   121  				Meta: meta,
   122  			}, nil
   123  		},
   124  
   125  		"server-members": func() (cli.Command, error) {
   126  			return &command.ServerMembersCommand{
   127  				Meta: meta,
   128  			}, nil
   129  		},
   130  		"status": func() (cli.Command, error) {
   131  			return &command.StatusCommand{
   132  				Meta: meta,
   133  			}, nil
   134  		},
   135  
   136  		"stop": func() (cli.Command, error) {
   137  			return &command.StopCommand{
   138  				Meta: meta,
   139  			}, nil
   140  		},
   141  
   142  		"validate": func() (cli.Command, error) {
   143  			return &command.ValidateCommand{
   144  				Meta: meta,
   145  			}, nil
   146  		},
   147  
   148  		"version": func() (cli.Command, error) {
   149  			ver := Version
   150  			rel := VersionPrerelease
   151  			if GitDescribe != "" {
   152  				ver = GitDescribe
   153  				// Trim off a leading 'v', we append it anyways.
   154  				if ver[0] == 'v' {
   155  					ver = ver[1:]
   156  				}
   157  			}
   158  			if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
   159  				rel = "dev"
   160  			}
   161  
   162  			return &command.VersionCommand{
   163  				Revision:          GitCommit,
   164  				Version:           ver,
   165  				VersionPrerelease: rel,
   166  				Ui:                meta.Ui,
   167  			}, nil
   168  		},
   169  	}
   170  }