github.com/naphatkrit/deis@v1.12.3/client/parser/tags.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  // Tags routes tags commands to their specific function
     9  func Tags(argv []string) error {
    10  	usage := `
    11  Valid commands for tags:
    12  
    13  tags:list        list tags for an app
    14  tags:set         set tags for an app
    15  tags:unset       unset tags for an app
    16  
    17  Use 'deis help [command]' to learn more.
    18  `
    19  
    20  	switch argv[0] {
    21  	case "tags:list":
    22  		return tagsList(argv)
    23  	case "tags:set":
    24  		return tagsSet(argv)
    25  	case "tags:unset":
    26  		return tagsUnset(argv)
    27  	default:
    28  		if printHelp(argv, usage) {
    29  			return nil
    30  		}
    31  
    32  		if argv[0] == "tags" {
    33  			argv[0] = "tags:list"
    34  			return tagsList(argv)
    35  		}
    36  
    37  		PrintUsage()
    38  		return nil
    39  	}
    40  }
    41  
    42  func tagsList(argv []string) error {
    43  	usage := `
    44  Lists tags for an application.
    45  
    46  Usage: deis tags:list [options]
    47  
    48  Options:
    49    -a --app=<app>
    50      the uniquely identifiable name of the application.
    51  `
    52  
    53  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    54  
    55  	if err != nil {
    56  		return err
    57  	}
    58  
    59  	return cmd.TagsList(safeGetValue(args, "--app"))
    60  }
    61  
    62  func tagsSet(argv []string) error {
    63  	usage := `
    64  Sets tags for an application.
    65  
    66  A tag is a key/value pair used to tag an application's containers and is passed to the
    67  scheduler. This is often used to restrict workloads to specific hosts matching the
    68  scheduler-configured metadata.
    69  
    70  Usage: deis tags:set [options] <key>=<value>...
    71  
    72  Arguments:
    73    <key> the tag key, for example: "environ" or "rack"
    74    <value> the tag value, for example: "prod" or "1"
    75  
    76  Options:
    77    -a --app=<app>
    78      the uniquely identifiable name for the application.
    79  `
    80  
    81  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    82  
    83  	if err != nil {
    84  		return err
    85  	}
    86  
    87  	app := safeGetValue(args, "--app")
    88  	tags := args["<key>=<value>"].([]string)
    89  
    90  	return cmd.TagsSet(app, tags)
    91  }
    92  
    93  func tagsUnset(argv []string) error {
    94  	usage := `
    95  Unsets tags for an application.
    96  
    97  Usage: deis tags:unset [options] <key>...
    98  
    99  Arguments:
   100    <key> the tag key to unset, for example: "environ" or "rack"
   101  
   102  Options:
   103    -a --app=<app>
   104      the uniquely identifiable name for the application.
   105  `
   106  
   107  	args, err := docopt.Parse(usage, argv, true, "", false, true)
   108  
   109  	if err != nil {
   110  		return err
   111  	}
   112  
   113  	app := safeGetValue(args, "--app")
   114  	tags := args["<key>"].([]string)
   115  
   116  	return cmd.TagsUnset(app, tags)
   117  }