Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
codegangsta committed Jul 20, 2013
1 parent a2844ae commit 518348e
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,42 @@ Make sure your PATH includes to the `$GOPATH/bin` directory so your commands can
export PATH=$PATH:$GOPATH/bin
```

## Getting Started
One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`.

``` go
package main

import "os"
import "github.com/codegangsta/cli"

func main() {
cli.NewApp().Run(os.Args)
}
```

This app will run and show help text, but is not very useful. Let's give an action to execute and some help documentation:

``` go
package main

import "os"
import "github.com/codegangsta/cli"

func main() {
app := cli.NewApp()
app.Name = "boom"
app.Usage = "make an explosive entrance"
app.Action = func(c *cli.Context) {
println("boom! I say!")
}

app.Run(os.Args)
}
```

Running this already gives you a ton of functionality, plus support for things like subcommands and flags, which are covered below.

## Example

Being a programmer can be a lonely job. Thankfully by the power of automation that is not the case! Let's create a greeter app to fend off our demons of loneliness!
Expand Down Expand Up @@ -81,7 +117,7 @@ You can lookup arguments by calling the `Args` function on cli.Context.

``` go
...
cli.Action = func(c *cli.Context) {
app.Action = func(c *cli.Context) {
println("Hello", c.Args()[0])
}
...
Expand All @@ -91,10 +127,10 @@ cli.Action = func(c *cli.Context) {
Setting and querying flags is simple.
``` go
...
cli.Flags = []cli.Flag {
app.Flags = []cli.Flag {
cli.StringFlag{"lang", "english", "language for the greeting"},
}
cli.Action = func(c *cli.Context) {
app.Action = func(c *cli.Context) {
if c.String("lang") == "spanish" {
println("Hola", c.Args()[0])
} else {
Expand All @@ -105,6 +141,8 @@ cli.Action = func(c *cli.Context) {
```

### Subcommands

Subcommands can be defined for a more git-like command line app.
WIP


Expand Down

0 comments on commit 518348e

Please sign in to comment.