Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 Client side of for Chrome Infra Package Deployer. | 6 Client side of for Chrome Infra Package Deployer. |
| 7 | 7 |
| 8 TODO: write more. | 8 TODO: write more. |
| 9 | 9 |
| 10 Subcommand starting with 'pkg-' are low level commands operating on package | 10 Subcommand starting with 'pkg-' are low level commands operating on package |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 59 |
| 60 // init initializes subcommand state (including global logger). It ensures all | 60 // init initializes subcommand state (including global logger). It ensures all |
| 61 // required positional and flag-like parameters are set. Returns true if they | 61 // required positional and flag-like parameters are set. Returns true if they |
| 62 // are, or false (and prints to stderr) if not. | 62 // are, or false (and prints to stderr) if not. |
| 63 func (c *Subcommand) init(args []string, minPosCount, maxPosCount int) bool { | 63 func (c *Subcommand) init(args []string, minPosCount, maxPosCount int) bool { |
| 64 // Check number of expected positional arguments. | 64 // Check number of expected positional arguments. |
| 65 if maxPosCount == 0 && len(args) != 0 { | 65 if maxPosCount == 0 && len(args) != 0 { |
| 66 c.printError(makeCLIError("unexpected arguments %v", args)) | 66 c.printError(makeCLIError("unexpected arguments %v", args)) |
| 67 return false | 67 return false |
| 68 } | 68 } |
| 69 » if len(args) < minPosCount || len(args) > maxPosCount { | 69 » if len(args) < minPosCount || (maxPosCount >= 0 && len(args) > maxPosCou nt) { |
| 70 var err error | 70 var err error |
| 71 if minPosCount == maxPosCount { | 71 if minPosCount == maxPosCount { |
| 72 err = makeCLIError("expecting %d positional argument, go t %d instead", minPosCount, len(args)) | 72 err = makeCLIError("expecting %d positional argument, go t %d instead", minPosCount, len(args)) |
| 73 } else { | 73 } else { |
| 74 » » » err = makeCLIError( | 74 » » » if maxPosCount >= 0 { |
| 75 » » » » "expecting from %d to %d positional arguments, g ot %d instead", | 75 » » » » err = makeCLIError( |
| 76 » » » » minPosCount, maxPosCount, len(args)) | 76 » » » » » "expecting from %d to %d positional argu ments, got %d instead", |
| 77 » » » » » minPosCount, maxPosCount, len(args)) | |
| 78 » » » } else { | |
| 79 » » » » err = makeCLIError( | |
| 80 » » » » » "expecting at least %d positional argume nts, got %d instead", | |
| 81 » » » » » minPosCount, len(args)) | |
| 82 » » » } | |
| 77 } | 83 } |
| 78 c.printError(err) | 84 c.printError(err) |
| 79 return false | 85 return false |
| 80 } | 86 } |
| 81 | 87 |
| 82 // Check required unset flags. | 88 // Check required unset flags. |
| 83 unset := []*flag.Flag{} | 89 unset := []*flag.Flag{} |
| 84 c.Flags.VisitAll(func(f *flag.Flag) { | 90 c.Flags.VisitAll(func(f *flag.Flag) { |
| 85 if strings.HasPrefix(f.DefValue, "<") && f.Value.String() == f.D efValue { | 91 if strings.HasPrefix(f.DefValue, "<") && f.Value.String() == f.D efValue { |
| 86 unset = append(unset, f) | 92 unset = append(unset, f) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 107 log = loggerConfig.Get() | 113 log = loggerConfig.Get() |
| 108 return true | 114 return true |
| 109 } | 115 } |
| 110 | 116 |
| 111 // printError prints error to stderr (recognizing commandLineError). | 117 // printError prints error to stderr (recognizing commandLineError). |
| 112 func (c *Subcommand) printError(err error) { | 118 func (c *Subcommand) printError(err error) { |
| 113 if _, ok := err.(commandLineError); ok { | 119 if _, ok := err.(commandLineError); ok { |
| 114 fmt.Fprintf(os.Stderr, "Bad command line: %s.\n\n", err) | 120 fmt.Fprintf(os.Stderr, "Bad command line: %s.\n\n", err) |
| 115 c.Flags.Usage() | 121 c.Flags.Usage() |
| 116 } else { | 122 } else { |
| 117 » » fmt.Fprintln(os.Stderr, err) | 123 » » fmt.Fprintf(os.Stderr, "Error: %s.\n", err) |
| 118 } | 124 } |
| 119 } | 125 } |
| 120 | 126 |
| 121 // writeJSONOutput writes result to JSON output file. It returns original error | 127 // writeJSONOutput writes result to JSON output file. It returns original error |
| 122 // if it is non-nil. | 128 // if it is non-nil. |
| 123 func (c *Subcommand) writeJSONOutput(result interface{}, err error) error { | 129 func (c *Subcommand) writeJSONOutput(result interface{}, err error) error { |
| 124 // -json-output flag wasn't specified. | 130 // -json-output flag wasn't specified. |
| 125 if c.jsonOutput == "" { | 131 if c.jsonOutput == "" { |
| 126 return err | 132 return err |
| 127 } | 133 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 // process exit code. | 169 // process exit code. |
| 164 func (c *Subcommand) done(result interface{}, err error) int { | 170 func (c *Subcommand) done(result interface{}, err error) int { |
| 165 err = c.writeJSONOutput(result, err) | 171 err = c.writeJSONOutput(result, err) |
| 166 if err != nil { | 172 if err != nil { |
| 167 c.printError(err) | 173 c.printError(err) |
| 168 return 1 | 174 return 1 |
| 169 } | 175 } |
| 170 return 0 | 176 return 0 |
| 171 } | 177 } |
| 172 | 178 |
| 179 // doneWithPins is a handy shortcut that prints array of pinOrError and deduces | |
|
nodir
2015/09/21 22:26:59
it is a slice, but whatever
Vadim Sh.
2015/09/29 01:43:34
renamed to "list"
| |
| 180 // process exit code based on presence of errors there. | |
| 181 func (c *Subcommand) doneWithPins(pins []pinOrError, err error) int { | |
| 182 if len(pins) == 0 { | |
| 183 fmt.Println("No packages.") | |
| 184 } else { | |
| 185 printPinsAndError(pins) | |
| 186 } | |
| 187 ret := c.done(pins, err) | |
| 188 if hasErrors(pins) && ret == 0 { | |
| 189 return 1 | |
| 190 } | |
| 191 return ret | |
| 192 } | |
| 193 | |
| 173 // commandLineError is used to tag errors related to CLI. | 194 // commandLineError is used to tag errors related to CLI. |
| 174 type commandLineError struct { | 195 type commandLineError struct { |
| 175 error | 196 error |
| 176 } | 197 } |
| 177 | 198 |
| 178 // makeCLIError returns new commandLineError. | 199 // makeCLIError returns new commandLineError. |
| 179 func makeCLIError(msg string, args ...interface{}) error { | 200 func makeCLIError(msg string, args ...interface{}) error { |
| 180 return commandLineError{fmt.Errorf(msg, args...)} | 201 return commandLineError{fmt.Errorf(msg, args...)} |
| 181 } | 202 } |
| 182 | 203 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 // batchOperation defines what to do with a packages matching a prefix. | 437 // batchOperation defines what to do with a packages matching a prefix. |
| 417 type batchOperation struct { | 438 type batchOperation struct { |
| 418 client cipd.Client | 439 client cipd.Client |
| 419 packagePrefix string // a package name or a prefix | 440 packagePrefix string // a package name or a prefix |
| 420 packages []string // packages to operate on, overrides packagePrefi x | 441 packages []string // packages to operate on, overrides packagePrefi x |
| 421 callback func(pkg string) (common.Pin, error) | 442 callback func(pkg string) (common.Pin, error) |
| 422 } | 443 } |
| 423 | 444 |
| 424 // pinOrError is passed through channels and also dumped to JSON results file. | 445 // pinOrError is passed through channels and also dumped to JSON results file. |
| 425 type pinOrError struct { | 446 type pinOrError struct { |
| 426 » Pkg string `json:"package"` | 447 » Pkg string `json:"package"` |
| 427 » Pin *common.Pin `json:"pin,omitempty"` | 448 » Pin *common.Pin `json:"pin,omitempty"` |
| 428 » Err string `json:"error,omitempty"` | 449 » Err string `json:"error,omitempty"` |
| 450 » Tracking string `json:"tracking,omitempty"` | |
| 429 } | 451 } |
| 430 | 452 |
| 431 // expandPkgDir takes a package name or '<prefix>/' and returns a list | 453 // expandPkgDir takes a package name or '<prefix>/' and returns a list |
| 432 // of matching packages (asking backend if necessary). Doesn't recurse, returns | 454 // of matching packages (asking backend if necessary). Doesn't recurse, returns |
| 433 // only direct children. | 455 // only direct children. |
| 434 func expandPkgDir(c cipd.Client, packagePrefix string) ([]string, error) { | 456 func expandPkgDir(c cipd.Client, packagePrefix string) ([]string, error) { |
| 435 if !strings.HasSuffix(packagePrefix, "/") { | 457 if !strings.HasSuffix(packagePrefix, "/") { |
| 436 return []string{packagePrefix}, nil | 458 return []string{packagePrefix}, nil |
| 437 } | 459 } |
| 438 pkgs, err := c.ListPackages(packagePrefix, false) | 460 pkgs, err := c.ListPackages(packagePrefix, false) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 459 if len(pkgs) == 0 { | 481 if len(pkgs) == 0 { |
| 460 var err error | 482 var err error |
| 461 pkgs, err = expandPkgDir(op.client, op.packagePrefix) | 483 pkgs, err = expandPkgDir(op.client, op.packagePrefix) |
| 462 if err != nil { | 484 if err != nil { |
| 463 return nil, err | 485 return nil, err |
| 464 } | 486 } |
| 465 } | 487 } |
| 466 return callConcurrently(pkgs, func(pkg string) pinOrError { | 488 return callConcurrently(pkgs, func(pkg string) pinOrError { |
| 467 pin, err := op.callback(pkg) | 489 pin, err := op.callback(pkg) |
| 468 if err != nil { | 490 if err != nil { |
| 469 » » » return pinOrError{pkg, nil, err.Error()} | 491 » » » return pinOrError{pkg, nil, err.Error(), ""} |
| 470 } | 492 } |
| 471 » » return pinOrError{pkg, &pin, ""} | 493 » » return pinOrError{pkg, &pin, "", ""} |
| 472 }), nil | 494 }), nil |
| 473 } | 495 } |
| 474 | 496 |
| 475 func callConcurrently(pkgs []string, callback func(pkg string) pinOrError) []pin OrError { | 497 func callConcurrently(pkgs []string, callback func(pkg string) pinOrError) []pin OrError { |
| 476 // Push index through channel to make results ordered as 'pkgs'. | 498 // Push index through channel to make results ordered as 'pkgs'. |
| 477 ch := make(chan struct { | 499 ch := make(chan struct { |
| 478 int | 500 int |
| 479 pinOrError | 501 pinOrError |
| 480 }) | 502 }) |
| 481 for idx, pkg := range pkgs { | 503 for idx, pkg := range pkgs { |
| 482 go func(idx int, pkg string) { | 504 go func(idx int, pkg string) { |
| 483 ch <- struct { | 505 ch <- struct { |
| 484 int | 506 int |
| 485 pinOrError | 507 pinOrError |
| 486 }{idx, callback(pkg)} | 508 }{idx, callback(pkg)} |
| 487 }(idx, pkg) | 509 }(idx, pkg) |
| 488 } | 510 } |
| 489 pins := make([]pinOrError, len(pkgs)) | 511 pins := make([]pinOrError, len(pkgs)) |
| 490 for i := 0; i < len(pkgs); i++ { | 512 for i := 0; i < len(pkgs); i++ { |
| 491 res := <-ch | 513 res := <-ch |
| 492 pins[res.int] = res.pinOrError | 514 pins[res.int] = res.pinOrError |
| 493 } | 515 } |
| 494 return pins | 516 return pins |
| 495 } | 517 } |
| 496 | 518 |
| 497 func printPinsAndError(pins []pinOrError) { | 519 func printPinsAndError(pins []pinOrError) { |
| 498 hasPins := false | 520 hasPins := false |
| 499 hasErrors := false | 521 hasErrors := false |
| 500 for _, p := range pins { | 522 for _, p := range pins { |
| 501 » » if p.Err == "" { | 523 » » if p.Err != "" { |
| 524 » » » hasErrors = true | |
| 525 » » } else if p.Pin != nil { | |
| 502 hasPins = true | 526 hasPins = true |
| 503 } else { | |
| 504 hasErrors = true | |
| 505 } | 527 } |
| 506 } | 528 } |
| 507 if hasPins { | 529 if hasPins { |
| 508 » » fmt.Println("Instances:") | 530 » » fmt.Println("Packages:") |
| 509 for _, p := range pins { | 531 for _, p := range pins { |
| 510 » » » if p.Err == "" { | 532 » » » if p.Err != "" || p.Pin == nil { |
| 533 » » » » continue | |
| 534 » » » } | |
| 535 » » » if p.Tracking == "" { | |
| 511 fmt.Printf(" %s\n", p.Pin) | 536 fmt.Printf(" %s\n", p.Pin) |
| 537 } else { | |
| 538 fmt.Printf(" %s (tracking %q)\n", p.Pin, p.Trac king) | |
| 512 } | 539 } |
| 513 } | 540 } |
| 514 } | 541 } |
| 515 if hasErrors { | 542 if hasErrors { |
| 516 fmt.Fprintln(os.Stderr, "Errors:") | 543 fmt.Fprintln(os.Stderr, "Errors:") |
| 517 for _, p := range pins { | 544 for _, p := range pins { |
| 518 if p.Err != "" { | 545 if p.Err != "" { |
| 519 » » » » fmt.Fprintf(os.Stderr, " %s\n", p.Err) | 546 » » » » fmt.Fprintf(os.Stderr, " %s: %s.\n", p.Pkg, p.E rr) |
| 520 } | 547 } |
| 521 } | 548 } |
| 522 } | 549 } |
| 523 } | 550 } |
| 524 | 551 |
| 525 func hasErrors(pins []pinOrError) bool { | 552 func hasErrors(pins []pinOrError) bool { |
| 526 for _, p := range pins { | 553 for _, p := range pins { |
| 527 if p.Err != "" { | 554 if p.Err != "" { |
| 528 return true | 555 return true |
| 529 } | 556 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 } | 606 } |
| 580 return registerInstanceFile(f.Name(), refsOpts, tagsOpts, serviceOpts) | 607 return registerInstanceFile(f.Name(), refsOpts, tagsOpts, serviceOpts) |
| 581 } | 608 } |
| 582 | 609 |
| 583 //////////////////////////////////////////////////////////////////////////////// | 610 //////////////////////////////////////////////////////////////////////////////// |
| 584 // 'ensure' subcommand. | 611 // 'ensure' subcommand. |
| 585 | 612 |
| 586 var cmdEnsure = &subcommands.Command{ | 613 var cmdEnsure = &subcommands.Command{ |
| 587 UsageLine: "ensure [options]", | 614 UsageLine: "ensure [options]", |
| 588 ShortDesc: "installs, removes and updates packages in one go", | 615 ShortDesc: "installs, removes and updates packages in one go", |
| 589 » LongDesc: "Installs, removes and updates packages in one go.", | 616 » LongDesc: "Installs, removes and updates packages in one go.\n\n" + |
| 617 » » "Supposed to be used from scripts and automation. Alternative to 'init', " + | |
| 618 » » "'install' and 'remove'. As such, it doesn't try to discover sit e root " + | |
| 619 » » "directory on its own.", | |
| 590 CommandRun: func() subcommands.CommandRun { | 620 CommandRun: func() subcommands.CommandRun { |
| 591 c := &ensureRun{} | 621 c := &ensureRun{} |
| 592 c.registerBaseFlags() | 622 c.registerBaseFlags() |
| 593 c.ServiceOptions.registerFlags(&c.Flags) | 623 c.ServiceOptions.registerFlags(&c.Flags) |
| 594 » » c.Flags.StringVar(&c.rootDir, "root", "<path>", "Path to a insta llation site root directory.") | 624 » » c.Flags.StringVar(&c.rootDir, "root", "<path>", "Path to an inst allation site root directory.") |
| 595 c.Flags.StringVar(&c.listFile, "list", "<path>", "A file with a list of '<package name> <version>' pairs.") | 625 c.Flags.StringVar(&c.listFile, "list", "<path>", "A file with a list of '<package name> <version>' pairs.") |
| 596 return c | 626 return c |
| 597 }, | 627 }, |
| 598 } | 628 } |
| 599 | 629 |
| 600 type ensureRun struct { | 630 type ensureRun struct { |
| 601 Subcommand | 631 Subcommand |
| 602 ServiceOptions | 632 ServiceOptions |
| 603 | 633 |
| 604 rootDir string | 634 rootDir string |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 Subcommand | 682 Subcommand |
| 653 ServiceOptions | 683 ServiceOptions |
| 654 | 684 |
| 655 version string | 685 version string |
| 656 } | 686 } |
| 657 | 687 |
| 658 func (c *resolveRun) Run(a subcommands.Application, args []string) int { | 688 func (c *resolveRun) Run(a subcommands.Application, args []string) int { |
| 659 if !c.init(args, 1, 1) { | 689 if !c.init(args, 1, 1) { |
| 660 return 1 | 690 return 1 |
| 661 } | 691 } |
| 662 » pins, err := resolveVersion(args[0], c.version, c.ServiceOptions) | 692 » return c.doneWithPins(resolveVersion(args[0], c.version, c.ServiceOption s)) |
| 663 » printPinsAndError(pins) | |
| 664 » ret := c.done(pins, err) | |
| 665 » if hasErrors(pins) && ret == 0 { | |
| 666 » » return 1 | |
| 667 » } | |
| 668 » return ret | |
| 669 } | 693 } |
| 670 | 694 |
| 671 func resolveVersion(packagePrefix, version string, serviceOpts ServiceOptions) ( []pinOrError, error) { | 695 func resolveVersion(packagePrefix, version string, serviceOpts ServiceOptions) ( []pinOrError, error) { |
| 672 client, err := serviceOpts.makeCipdClient("") | 696 client, err := serviceOpts.makeCipdClient("") |
| 673 if err != nil { | 697 if err != nil { |
| 674 return nil, err | 698 return nil, err |
| 675 } | 699 } |
| 676 return performBatchOperation(batchOperation{ | 700 return performBatchOperation(batchOperation{ |
| 677 client: client, | 701 client: client, |
| 678 packagePrefix: packagePrefix, | 702 packagePrefix: packagePrefix, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 707 version string | 731 version string |
| 708 } | 732 } |
| 709 | 733 |
| 710 func (c *setRefRun) Run(a subcommands.Application, args []string) int { | 734 func (c *setRefRun) Run(a subcommands.Application, args []string) int { |
| 711 if !c.init(args, 1, 1) { | 735 if !c.init(args, 1, 1) { |
| 712 return 1 | 736 return 1 |
| 713 } | 737 } |
| 714 if len(c.refs) == 0 { | 738 if len(c.refs) == 0 { |
| 715 return c.done(nil, makeCLIError("at least one -ref must be provi ded")) | 739 return c.done(nil, makeCLIError("at least one -ref must be provi ded")) |
| 716 } | 740 } |
| 717 » pins, err := setRef(args[0], c.version, c.RefsOptions, c.ServiceOptions) | 741 » return c.doneWithPins(setRef(args[0], c.version, c.RefsOptions, c.Servic eOptions)) |
| 718 » printPinsAndError(pins) | |
| 719 » ret := c.done(pins, err) | |
| 720 » if hasErrors(pins) && ret == 0 { | |
| 721 » » return 1 | |
| 722 » } | |
| 723 » return ret | |
| 724 } | 742 } |
| 725 | 743 |
| 726 func setRef(packagePrefix, version string, refsOpts RefsOptions, serviceOpts Ser viceOptions) ([]pinOrError, error) { | 744 func setRef(packagePrefix, version string, refsOpts RefsOptions, serviceOpts Ser viceOptions) ([]pinOrError, error) { |
| 727 client, err := serviceOpts.makeCipdClient("") | 745 client, err := serviceOpts.makeCipdClient("") |
| 728 if err != nil { | 746 if err != nil { |
| 729 return nil, err | 747 return nil, err |
| 730 } | 748 } |
| 731 | 749 |
| 732 // Do not touch anything if some packages do not have requested version. So | 750 // Do not touch anything if some packages do not have requested version. So |
| 733 // resolve versions first and only then move refs. | 751 // resolve versions first and only then move refs. |
| 734 pins, err := performBatchOperation(batchOperation{ | 752 pins, err := performBatchOperation(batchOperation{ |
| 735 client: client, | 753 client: client, |
| 736 packagePrefix: packagePrefix, | 754 packagePrefix: packagePrefix, |
| 737 callback: func(pkg string) (common.Pin, error) { | 755 callback: func(pkg string) (common.Pin, error) { |
| 738 return client.ResolveVersion(pkg, version) | 756 return client.ResolveVersion(pkg, version) |
| 739 }, | 757 }, |
| 740 }) | 758 }) |
| 741 if err != nil { | 759 if err != nil { |
| 742 return nil, err | 760 return nil, err |
| 743 } | 761 } |
| 744 if hasErrors(pins) { | 762 if hasErrors(pins) { |
| 745 printPinsAndError(pins) | 763 printPinsAndError(pins) |
| 746 » » return nil, fmt.Errorf("can't find %q version in all packages, a borting.", version) | 764 » » return nil, fmt.Errorf("can't find %q version in all packages, a borting", version) |
| 747 } | 765 } |
| 748 | 766 |
| 749 // Prepare for the next batch call. | 767 // Prepare for the next batch call. |
| 750 packages := []string{} | 768 packages := []string{} |
| 751 pinsToUse := map[string]common.Pin{} | 769 pinsToUse := map[string]common.Pin{} |
| 752 for _, p := range pins { | 770 for _, p := range pins { |
| 753 packages = append(packages, p.Pkg) | 771 packages = append(packages, p.Pkg) |
| 754 pinsToUse[p.Pkg] = *p.Pin | 772 pinsToUse[p.Pkg] = *p.Pin |
| 755 } | 773 } |
| 756 | 774 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 768 return pin, nil | 786 return pin, nil |
| 769 }, | 787 }, |
| 770 }) | 788 }) |
| 771 } | 789 } |
| 772 | 790 |
| 773 //////////////////////////////////////////////////////////////////////////////// | 791 //////////////////////////////////////////////////////////////////////////////// |
| 774 // 'ls' subcommand. | 792 // 'ls' subcommand. |
| 775 | 793 |
| 776 var cmdListPackages = &subcommands.Command{ | 794 var cmdListPackages = &subcommands.Command{ |
| 777 UsageLine: "ls [-r] [<prefix string>]", | 795 UsageLine: "ls [-r] [<prefix string>]", |
| 778 » ShortDesc: "lists matching packages", | 796 » ShortDesc: "queries backend for a list of matching packages", |
|
nodir
2015/09/21 22:26:59
looks like mentioning impl details. I'd move them
Vadim Sh.
2015/09/29 01:43:34
Done. I wanted to clarify that it lists packages o
tandrii(chromium)
2015/09/29 14:21:25
weak suggestion: maybe then say in short version "
| |
| 779 LongDesc: "List packages in the given path to which the user has access , optionally recursively.", | 797 LongDesc: "List packages in the given path to which the user has access , optionally recursively.", |
| 780 CommandRun: func() subcommands.CommandRun { | 798 CommandRun: func() subcommands.CommandRun { |
| 781 c := &listPackagesRun{} | 799 c := &listPackagesRun{} |
| 782 c.registerBaseFlags() | 800 c.registerBaseFlags() |
| 783 c.ServiceOptions.registerFlags(&c.Flags) | 801 c.ServiceOptions.registerFlags(&c.Flags) |
| 784 c.Flags.BoolVar(&c.recursive, "r", false, "Whether to list packa ges in subdirectories.") | 802 c.Flags.BoolVar(&c.recursive, "r", false, "Whether to list packa ges in subdirectories.") |
| 785 return c | 803 return c |
| 786 }, | 804 }, |
| 787 } | 805 } |
| 788 | 806 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 //////////////////////////////////////////////////////////////////////////////// | 1058 //////////////////////////////////////////////////////////////////////////////// |
| 1041 // 'pkg-deploy' subcommand. | 1059 // 'pkg-deploy' subcommand. |
| 1042 | 1060 |
| 1043 var cmdDeploy = &subcommands.Command{ | 1061 var cmdDeploy = &subcommands.Command{ |
| 1044 UsageLine: "pkg-deploy <package instance file> [options]", | 1062 UsageLine: "pkg-deploy <package instance file> [options]", |
| 1045 ShortDesc: "deploys a package instance file", | 1063 ShortDesc: "deploys a package instance file", |
| 1046 LongDesc: "Deploys a *.cipd package instance into a site root.", | 1064 LongDesc: "Deploys a *.cipd package instance into a site root.", |
| 1047 CommandRun: func() subcommands.CommandRun { | 1065 CommandRun: func() subcommands.CommandRun { |
| 1048 c := &deployRun{} | 1066 c := &deployRun{} |
| 1049 c.registerBaseFlags() | 1067 c.registerBaseFlags() |
| 1050 » » c.Flags.StringVar(&c.rootDir, "root", "<path>", "Path to a insta llation site root directory.") | 1068 » » c.Flags.StringVar(&c.rootDir, "root", "<path>", "Path to an inst allation site root directory.") |
| 1051 return c | 1069 return c |
| 1052 }, | 1070 }, |
| 1053 } | 1071 } |
| 1054 | 1072 |
| 1055 type deployRun struct { | 1073 type deployRun struct { |
| 1056 Subcommand | 1074 Subcommand |
| 1057 | 1075 |
| 1058 rootDir string | 1076 rootDir string |
| 1059 } | 1077 } |
| 1060 | 1078 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1263 //////////////////////////////////////////////////////////////////////////////// | 1281 //////////////////////////////////////////////////////////////////////////////// |
| 1264 // Main. | 1282 // Main. |
| 1265 | 1283 |
| 1266 var application = &subcommands.DefaultApplication{ | 1284 var application = &subcommands.DefaultApplication{ |
| 1267 Name: "cipd", | 1285 Name: "cipd", |
| 1268 Title: "Chrome Infra Package Deployer", | 1286 Title: "Chrome Infra Package Deployer", |
| 1269 Commands: []*subcommands.Command{ | 1287 Commands: []*subcommands.Command{ |
| 1270 subcommands.CmdHelp, | 1288 subcommands.CmdHelp, |
| 1271 cipd_lib.SubcommandVersion, | 1289 cipd_lib.SubcommandVersion, |
| 1272 | 1290 |
| 1291 // User friendly subcommands that operates within a site root. I mplemented | |
| 1292 // in friendly.go. | |
| 1293 cmdInit, | |
| 1294 cmdInstall, | |
| 1295 cmdInstalled, | |
| 1296 | |
| 1273 // Authentication related commands. | 1297 // Authentication related commands. |
| 1274 authcli.SubcommandInfo(auth.Options{Logger: log}, "auth-info"), | 1298 authcli.SubcommandInfo(auth.Options{Logger: log}, "auth-info"), |
| 1275 authcli.SubcommandLogin(auth.Options{Logger: log}, "auth-login") , | 1299 authcli.SubcommandLogin(auth.Options{Logger: log}, "auth-login") , |
| 1276 authcli.SubcommandLogout(auth.Options{Logger: log}, "auth-logout "), | 1300 authcli.SubcommandLogout(auth.Options{Logger: log}, "auth-logout "), |
| 1277 | 1301 |
| 1278 // High level commands. | 1302 // High level commands. |
| 1279 cmdListPackages, | 1303 cmdListPackages, |
| 1280 cmdCreate, | 1304 cmdCreate, |
| 1281 cmdEnsure, | 1305 cmdEnsure, |
| 1282 cmdResolve, | 1306 cmdResolve, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 newArgs = append(newArgs, cmd) | 1352 newArgs = append(newArgs, cmd) |
| 1329 } | 1353 } |
| 1330 newArgs = append(newArgs, flags...) | 1354 newArgs = append(newArgs, flags...) |
| 1331 newArgs = append(newArgs, positional...) | 1355 newArgs = append(newArgs, positional...) |
| 1332 return newArgs | 1356 return newArgs |
| 1333 } | 1357 } |
| 1334 | 1358 |
| 1335 func main() { | 1359 func main() { |
| 1336 os.Exit(subcommands.Run(application, fixFlagsPosition(os.Args[1:]))) | 1360 os.Exit(subcommands.Run(application, fixFlagsPosition(os.Args[1:]))) |
| 1337 } | 1361 } |
| OLD | NEW |