-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b09eae
commit 5dcef27
Showing
5 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
go1.22.6 | ||
go1.23.1 |
57 changes: 57 additions & 0 deletions
57
generated_src/internal/amalgomated_flag/example_flagset_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package flag_test | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func ExampleFlagSet() { | ||
|
||
start := func(args []string) { | ||
// A real program (not an example) would use flag.ExitOnError. | ||
fs := flag.NewFlagSet("start", flag.ContinueOnError) | ||
addr := fs.String("addr", ":8080", "`address` to listen on") | ||
if err := fs.Parse(args); err != nil { | ||
fmt.Printf("error: %s", err) | ||
return | ||
} | ||
fmt.Printf("starting server on %s\n", *addr) | ||
} | ||
|
||
stop := func(args []string) { | ||
fs := flag.NewFlagSet("stop", flag.ContinueOnError) | ||
timeout := fs.Duration("timeout", time.Second, "stop timeout duration") | ||
if err := fs.Parse(args); err != nil { | ||
fmt.Printf("error: %s", err) | ||
return | ||
} | ||
fmt.Printf("stopping server (timeout=%v)\n", *timeout) | ||
} | ||
|
||
main := func(args []string) { | ||
subArgs := args[2:] // Drop program name and command. | ||
switch args[1] { | ||
case "start": | ||
start(subArgs) | ||
case "stop": | ||
stop(subArgs) | ||
default: | ||
fmt.Printf("error: unknown command - %q\n", args[1]) | ||
// In a real program (not an example) print to os.Stderr and exit the program with non-zero value. | ||
} | ||
} | ||
|
||
main([]string{"httpd", "start", "-addr", ":9999"}) | ||
main([]string{"httpd", "stop"}) | ||
main([]string{"http", "start", "-log-level", "verbose"}) | ||
|
||
// Output: | ||
// starting server on :9999 | ||
// stopping server (timeout=1s) | ||
// error: flag provided but not defined: -log-level | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters