Skip to content

Commit 659f3c4

Browse files
authored
Merge pull request #26 from coder/readme-improvements
2 parents e5798f5 + cd5122d commit 659f3c4

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,49 @@ type Option struct {
9191
And is used by each [Command](https://pkg.go.dev/github.com/coder/serpent#Command) when
9292
passed as an array to the `Options` field.
9393

94-
## More coming...
95-
This README is a stub for now. We'll better explain the design and usage
96-
of `serpent` in the future.
94+
## Comparison with Cobra
95+
96+
Here is a comparison of the `help` output between a simple `echo` command in Cobra and Serpent.
97+
98+
### Cobra
99+
100+
```
101+
echo is for echoing anything back. Echo works a lot like print, except it has a child command.
102+
103+
Usage:
104+
echo [string to echo] [flags]
105+
106+
Flags:
107+
-h, --help help for echo
108+
-u, --upper make the output uppercase
109+
```
110+
111+
### Serpent
112+
113+
```
114+
USAGE:
115+
echo <text>
116+
117+
Prints the given text to the console.
118+
119+
OPTIONS:
120+
--upper bool
121+
Prints the text in upper case.
122+
```
123+
124+
## Migrating from Cobra
125+
126+
Serpent is designed to be a replacement for Cobra and Viper. If you are familiar with Cobra, the transition to Serpent should be relatively straightforward. The main differences are:
127+
128+
* **Command Structure:** Serpent uses a `serpent.Command` struct which is similar to `cobra.Command`.
129+
* **Options:** Serpent has a more flexible and powerful option system that allows you to define options from multiple sources (flags, environment variables, config files, etc.) in a single place.
130+
* **Middleware:** Serpent has a middleware system that allows you to compose functionality and apply it to your commands.
131+
* **Testability:** Serpent is designed to be more testable than Cobra. For example, OS stdout and stderr are only available to commands explicitly.
132+
133+
## Serpent vs. Cobra and Viper
134+
135+
Serpent is intended to be a complete replacement for both Cobra and Viper. While Viper is often used with Cobra to provide environment and config file support, Serpent has this functionality built-in. This results in a more integrated and streamlined experience.
136+
137+
## Examples
138+
139+
For a more comprehensive example of a large-scale CLI built with Serpent, please see the [coder/coder](https://github.com/coder/coder) repository.

0 commit comments

Comments
 (0)