github.com/naphatkrit/deis@v1.12.3/client/parser/ps.go (about)

     1  package parser
     2  
     3  import (
     4  	"github.com/deis/deis/client/cmd"
     5  	docopt "github.com/docopt/docopt-go"
     6  )
     7  
     8  // Ps routes ps commands to their specific function.
     9  func Ps(argv []string) error {
    10  	usage := `
    11  Valid commands for processes:
    12  
    13  ps:list        list application processes
    14  ps:restart     restart an application or its process types
    15  ps:scale       scale processes (e.g. web=4 worker=2)
    16  
    17  Use 'deis help [command]' to learn more.
    18  `
    19  
    20  	switch argv[0] {
    21  	case "ps:list":
    22  		return psList(argv)
    23  	case "ps:restart":
    24  		return psRestart(argv)
    25  	case "ps:scale":
    26  		return psScale(argv)
    27  	default:
    28  		if printHelp(argv, usage) {
    29  			return nil
    30  		}
    31  
    32  		if argv[0] == "ps" {
    33  			argv[0] = "ps:list"
    34  			return psList(argv)
    35  		}
    36  
    37  		PrintUsage()
    38  		return nil
    39  	}
    40  }
    41  
    42  func psList(argv []string) error {
    43  	usage := `
    44  Lists processes servicing an application.
    45  
    46  Usage: deis ps:list [options]
    47  
    48  Options:
    49    -a --app=<app>
    50      the uniquely identifiable name for the application.
    51    -l --limit=<num>
    52      the maximum number of results to display, defaults to config setting
    53  `
    54  
    55  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    56  
    57  	if err != nil {
    58  		return err
    59  	}
    60  
    61  	results, err := responseLimit(safeGetValue(args, "--limit"))
    62  
    63  	if err != nil {
    64  		return err
    65  	}
    66  
    67  	return cmd.PsList(safeGetValue(args, "--app"), results)
    68  }
    69  
    70  func psRestart(argv []string) error {
    71  	usage := `
    72  Restart an application, a process type or a specific process.
    73  
    74  Usage: deis ps:restart [<type>] [options]
    75  
    76  Arguments:
    77    <type>
    78      the process name as defined in your Procfile, such as 'web' or 'worker'.
    79      To restart a particular process, use 'web.1'.
    80  
    81  Options:
    82    -a --app=<app>
    83      the uniquely identifiable name for the application.
    84  `
    85  
    86  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    87  
    88  	if err != nil {
    89  		return err
    90  	}
    91  
    92  	return cmd.PsRestart(safeGetValue(args, "--app"), safeGetValue(args, "<type>"))
    93  }
    94  
    95  func psScale(argv []string) error {
    96  	usage := `
    97  Scales an application's processes by type.
    98  
    99  Usage: deis ps:scale <type>=<num>... [options]
   100  
   101  Arguments:
   102    <type>
   103      the process name as defined in your Procfile, such as 'web' or 'worker'.
   104      Note that Dockerfile apps have a default 'cmd' process type.
   105    <num>
   106      the number of processes.
   107  
   108  Options:
   109    -a --app=<app>
   110      the uniquely identifiable name for the application.
   111  `
   112  
   113  	args, err := docopt.Parse(usage, argv, true, "", false, true)
   114  
   115  	if err != nil {
   116  		return err
   117  	}
   118  
   119  	return cmd.PsScale(safeGetValue(args, "--app"), args["<type>=<num>"].([]string))
   120  }