kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/util/cmdutil/cmdutil_test.go (about) 1 /* 2 * Copyright 2018 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmdutil_test 18 19 import ( 20 "context" 21 "flag" 22 "fmt" 23 24 "github.com/google/subcommands" 25 "kythe.io/kythe/go/util/cmdutil" 26 ) 27 28 func ExampleNewInfo() { 29 cmd := struct { 30 cmdutil.Info 31 }{ 32 Info: cmdutil.NewInfo("example", "Demonstrate how to set up a subcommand", 33 `Show the user how to use the cmdutil.NewInfo function.`), 34 } 35 36 // Set up a flag set for demo purposes; most tools will use the default 37 // command line flags from the flag package. 38 fs := flag.NewFlagSet("test", flag.ExitOnError) 39 fs.Parse([]string{"example", "foo"}) 40 41 // Register a command with the dispatcher. 42 cmdr := subcommands.NewCommander(fs, "cmdutil_test") 43 cmdr.Register(cmd, "examples") 44 45 // Execute... 46 fmt.Println(cmdr.Execute(context.Background(), fs)) 47 // Output: 48 // Show the user how to use the cmdutil.NewInfo function. 49 // 0 50 }