commit
fed41d6ef8
@ -28,6 +28,7 @@ cli v2 manual
|
|||||||
+ [Customization](#customization-1)
|
+ [Customization](#customization-1)
|
||||||
* [Version Flag](#version-flag)
|
* [Version Flag](#version-flag)
|
||||||
+ [Customization](#customization-2)
|
+ [Customization](#customization-2)
|
||||||
|
* [Timestamp Flag](#timestamp-flag)
|
||||||
* [Full API Example](#full-api-example)
|
* [Full API Example](#full-api-example)
|
||||||
|
|
||||||
<!-- tocstop -->
|
<!-- tocstop -->
|
||||||
@ -1273,6 +1274,49 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Timestamp Flag
|
||||||
|
|
||||||
|
Using the timestamp flag is simple. Please refer to [`time.Parse`](https://golang.org/pkg/time/#example_Parse) to get possible formats.
|
||||||
|
|
||||||
|
<!-- {
|
||||||
|
"args": ["--meeting", "2019-08-12T15:04:05"],
|
||||||
|
"output": "2019\\-08\\-12 15\\:04\\:05 \\+0000 UTC"
|
||||||
|
} -->
|
||||||
|
``` go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := &cli.App{
|
||||||
|
Flags: []cli.Flag {
|
||||||
|
&cli.TimestampFlag{Name: "meeting", Layout: "2006-01-02T15:04:05"},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
fmt.Printf("%s", c.Timestamp("meeting").String())
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example the flag could be used like this :
|
||||||
|
|
||||||
|
`myapp --meeting 2019-08-12T15:04:05`
|
||||||
|
|
||||||
|
Side note: quotes may be necessary around the date depending on your layout (if you have spaces for instance)
|
||||||
|
|
||||||
### Full API Example
|
### Full API Example
|
||||||
|
|
||||||
**Notice**: This is a contrived (functioning) example meant strictly for API
|
**Notice**: This is a contrived (functioning) example meant strictly for API
|
||||||
|
Loading…
Reference in New Issue
Block a user