Skip to content

Commit 86204ce

Browse files
committed
Update doc.go and examples
1 parent 54b6f94 commit 86204ce

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

doc.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
1-
// Package cli provides a lightweight framework for building command-line applications. It features
2-
// nested subcommand support and flexible flag parsing.
1+
// Package cli provides a lightweight framework for building command-line applications using Go's
2+
// standard library flag package. It extends flag functionality to support flags anywhere in command
3+
// arguments.
34
//
4-
// The package prioritizes simplicity and ease of use, making it an ideal foundation for CLI
5-
// applications that don't require the overhead of larger frameworks. This focused design allows
6-
// developers to concentrate on their application's core functionality while keeping their code
7-
// simple and maintainable.
5+
// Key features:
6+
// - Nested subcommands for organizing complex CLIs
7+
// - Flexible flag parsing, allowing flags anywhere in arguments
8+
// - Parent-to-child flag inheritance
9+
// - Type-safe flag access
10+
// - Automatic help text generation
11+
// - Command suggestions for misspelled inputs
12+
//
13+
// Quick example:
14+
//
15+
// root := &cli.Command{
16+
// Name: "echo",
17+
// Usage: "echo [flags] <text>...",
18+
// ShortHelp: "prints the provided text",
19+
// Flags: cli.FlagsFunc(func(f *flag.FlagSet) {
20+
// f.Bool("c", false, "capitalize the input")
21+
// }),
22+
// Exec: func(ctx context.Context, s *cli.State) error {
23+
// output := strings.Join(s.Args, " ")
24+
// if cli.GetFlag[bool](s, "c") {
25+
// output = strings.ToUpper(output)
26+
// }
27+
// fmt.Fprintln(s.Stdout, output)
28+
// return nil
29+
// },
30+
// }
31+
//
32+
// The package intentionally maintains a minimal API surface to serve as a building block for CLI
33+
// applications while leveraging the standard library's flag package. This approach enables
34+
// developers to build maintainable command-line tools quickly while focusing on application logic
35+
// rather than framework complexity.
836
package cli

examples/cmd/task/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
// ├── add <text>
2626
// │ └── (-tags)
2727
// ├── done <id>
28-
// └── remove <id>
28+
// └── remove <id> (-force, -all)
2929

3030
func main() {
3131
root := &cli.Command{

examples/cmd/task/tasks.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ func (l *TaskList) Add(t Task) {
4646
l.Tasks = append(l.Tasks, t)
4747
}
4848

49-
func (l *TaskList) Remove(id int) {
49+
func (l *TaskList) Remove(id int) error {
5050
for i, t := range l.Tasks {
5151
if t.ID == id {
5252
l.Tasks = append(l.Tasks[:i], l.Tasks[i+1:]...)
53-
return
53+
return nil
5454
}
5555
}
56+
return fmt.Errorf("task with ID %d not found", id)
5657
}
5758

5859
func (l *TaskList) List() []Task {

0 commit comments

Comments
 (0)