Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: go/src/infra/tools/cr/lib/subcommand/subcommand.go

Issue 1929153002: Add beginnings of new cr command (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /*
6 Library for defining subcommands in a structured way.
7 */
8
9 package subcommand
10
11 import (
12 "flag"
13 "fmt"
14 )
15
16 type Subcommand struct {
17 ShortHelp string
18 LongHelp string
19 flagFn func(*flag.FlagSet)
20 runFn func(*flag.FlagSet) error
21 }
22
23 func New(shortHelp string, longHelp string, flagFn func(*flag.FlagSet), runFn fu nc(*flag.FlagSet) error) *Subcommand {
24 return &Subcommand{shortHelp, longHelp, flagFn, runFn}
25 }
26
27 func (c *Subcommand) Help(flags *flag.FlagSet) {
28 fmt.Println(c.ShortHelp)
29 fmt.Println("")
30 fmt.Println(c.LongHelp)
31 fmt.Println("")
32 flags.PrintDefaults()
33 }
34
35 func (c *Subcommand) InitFlags(flags *flag.FlagSet) {
36 if c.flagFn != nil {
37 c.flagFn(flags)
38 }
39 }
40
41 func (c *Subcommand) Run(flags *flag.FlagSet) error {
42 if c.runFn != nil {
43 return c.runFn(flags)
44 }
45 return nil
46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698