github.com/naphatkrit/deis@v1.12.3/client/parser/domains.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  // Domains routes domain commands to their specific function.
     9  func Domains(argv []string) error {
    10  	usage := `
    11  Valid commands for domains:
    12  
    13  domains:add           bind a domain to an application
    14  domains:list          list domains bound to an application
    15  domains:remove        unbind a domain from an application
    16  
    17  Use 'deis help [command]' to learn more.
    18  `
    19  	switch argv[0] {
    20  	case "domains:add":
    21  		return domainsAdd(argv)
    22  	case "domains:list":
    23  		return domainsList(argv)
    24  	case "domains:remove":
    25  		return domainsRemove(argv)
    26  	default:
    27  		if printHelp(argv, usage) {
    28  			return nil
    29  		}
    30  
    31  		if argv[0] == "domains" {
    32  			argv[0] = "domains:list"
    33  			return domainsList(argv)
    34  		}
    35  
    36  		PrintUsage()
    37  		return nil
    38  	}
    39  }
    40  
    41  func domainsAdd(argv []string) error {
    42  	usage := `
    43  Binds a domain to an application.
    44  
    45  Usage: deis domains:add <domain> [options]
    46  
    47  Arguments:
    48    <domain>
    49      the domain name to be bound to the application, such as 'domain.deisapp.com'.
    50  
    51  Options:
    52    -a --app=<app>
    53      the uniquely identifiable name for the application.
    54  `
    55  
    56  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    57  
    58  	if err != nil {
    59  		return err
    60  	}
    61  
    62  	return cmd.DomainsAdd(safeGetValue(args, "--app"), safeGetValue(args, "<domain>"))
    63  }
    64  
    65  func domainsList(argv []string) error {
    66  	usage := `
    67  Lists domains bound to an application.
    68  
    69  Usage: deis domains:list [options]
    70  
    71  Options:
    72    -a --app=<app>
    73      the uniquely identifiable name for the application.
    74    -l --limit=<num>
    75      the maximum number of results to display, defaults to config setting
    76  `
    77  
    78  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    79  
    80  	if err != nil {
    81  		return err
    82  	}
    83  
    84  	results, err := responseLimit(safeGetValue(args, "--limit"))
    85  
    86  	if err != nil {
    87  		return err
    88  	}
    89  
    90  	return cmd.DomainsList(safeGetValue(args, "--app"), results)
    91  }
    92  
    93  func domainsRemove(argv []string) error {
    94  	usage := `
    95  Unbinds a domain for an application.
    96  
    97  Usage: deis domains:remove <domain> [options]
    98  
    99  Arguments:
   100    <domain>
   101      the domain name to be removed from the application.
   102  
   103  Options:
   104    -a --app=<app>
   105      the uniquely identifiable name for the application.
   106  `
   107  
   108  	args, err := docopt.Parse(usage, argv, true, "", false, true)
   109  
   110  	if err != nil {
   111  		return err
   112  	}
   113  
   114  	return cmd.DomainsRemove(safeGetValue(args, "--app"), safeGetValue(args, "<domain>"))
   115  }