From f581ba6c58b834504a87f8906cf639da00ada43d Mon Sep 17 00:00:00 2001 From: Martin Lees Date: Wed, 18 Dec 2019 17:35:29 +0100 Subject: [PATCH 1/9] Add timestampFlag docs Reason for this PR is that it makes the CI fail until #987 is merged --- docs/v2/manual.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 5e04d4e..39c1baf 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1150,6 +1150,45 @@ The default version flag (`-v/--version`) is defined as `cli.VersionFlag`, which is checked by the cli internals in order to print the `App.Version` via `cli.VersionPrinter` and break execution. + +### Timestamp Flag + +Using the timestamp flag is simple, You can look at time.Parse to get layout examples : https://golang.org/pkg/time/#example_Parse + + +``` 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("%#v",c.Timestamp("meeting").String()) + return nil + }, + } + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} +``` + + #### Customization The default flag may be customized to something other than `-v/--version` by From e264ede3522b82c0192dc899207099c6fc381ee5 Mon Sep 17 00:00:00 2001 From: Martin Lees Date: Wed, 18 Dec 2019 23:02:14 +0100 Subject: [PATCH 2/9] Update manual.md --- docs/v2/manual.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 39c1baf..48179e0 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1188,6 +1188,12 @@ func main() { } ``` +In this example the flag could be used like so : + +`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) + #### Customization From 21ae70fe62cafb7c2535ec4cdcd84b38765126dc Mon Sep 17 00:00:00 2001 From: Martin Lees Date: Sat, 28 Dec 2019 23:41:32 +0100 Subject: [PATCH 3/9] Removed trailing " that makes ci fail Editing this on my phone, not 100% sure if this will work but we'll see --- docs/v2/manual.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 4d019b8..8ccdd48 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1215,7 +1215,7 @@ Using the timestamp flag is simple, You can look at time.Parse to get layout exa ``` go package main From 4c4f52c2b7bbcbcc55085fb2a14e96e5b880d393 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 26 Jan 2020 19:07:37 +0530 Subject: [PATCH 4/9] fix unexpected end of JSON input --- docs/v2/manual.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 8ccdd48..4d019b8 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1215,7 +1215,7 @@ Using the timestamp flag is simple, You can look at time.Parse to get layout exa ``` go package main From ec94e0e667635ad4e83f1dd84a940a7a302d9a00 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 26 Jan 2020 19:15:30 +0530 Subject: [PATCH 5/9] fix problem with quotations --- docs/v2/manual.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 4d019b8..915c0e2 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1215,7 +1215,7 @@ Using the timestamp flag is simple, You can look at time.Parse to get layout exa ``` go package main @@ -1234,7 +1234,7 @@ func main() { &cli.TimestampFlag{Name: "meeting", Layout: "2006-01-02T15:04:05"}, }, Action: func(c *cli.Context) error { - fmt.Printf("%#v",c.Timestamp("meeting").String()) + fmt.Printf("%v",c.Timestamp("meeting").String()) return nil }, } From 1c57160c236d7978ba8d0ad91cdee2d4d2c8ddd3 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 26 Jan 2020 19:19:11 +0530 Subject: [PATCH 6/9] Update manual.md --- docs/v2/manual.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 915c0e2..7e07fd6 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1234,7 +1234,7 @@ func main() { &cli.TimestampFlag{Name: "meeting", Layout: "2006-01-02T15:04:05"}, }, Action: func(c *cli.Context) error { - fmt.Printf("%v",c.Timestamp("meeting").String()) + fmt.Println(c.Timestamp("meeting").String()) return nil }, } From 1efee6b1daae2b198b4d574cf4c0a8b0442f0c36 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 26 Jan 2020 19:45:04 +0530 Subject: [PATCH 7/9] docs test expects a regex of output --- docs/v2/manual.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 7e07fd6..7d62546 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1215,7 +1215,7 @@ Using the timestamp flag is simple, You can look at time.Parse to get layout exa ``` go package main @@ -1234,7 +1234,7 @@ func main() { &cli.TimestampFlag{Name: "meeting", Layout: "2006-01-02T15:04:05"}, }, Action: func(c *cli.Context) error { - fmt.Println(c.Timestamp("meeting").String()) + fmt.Printf("%s", c.Timestamp("meeting").String()) return nil }, } From f497fa3b9f9492d7d5ea9dc82dd75526cde80d82 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 26 Jan 2020 19:49:43 +0530 Subject: [PATCH 8/9] fix order of placement and toc --- docs/v2/manual.md | 89 +++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 7d62546..9f338cd 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -28,6 +28,7 @@ cli v2 manual + [Customization](#customization-1) * [Version Flag](#version-flag) + [Customization](#customization-2) + * [Timestamp Flag](#timestamp-flag) * [Full API Example](#full-api-example) @@ -1208,51 +1209,6 @@ The default version flag (`-v/--version`) is defined as `cli.VersionFlag`, which is checked by the cli internals in order to print the `App.Version` via `cli.VersionPrinter` and break execution. - -### Timestamp Flag - -Using the timestamp flag is simple, You can look at time.Parse to get layout examples : https://golang.org/pkg/time/#example_Parse - - -``` 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 so : - -`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) - - #### Customization The default flag may be customized to something other than `-v/--version` by @@ -1318,6 +1274,49 @@ func main() { } ``` +### Timestamp Flag + +Using the timestamp flag is simple, You can look at time.Parse to get layout examples : https://golang.org/pkg/time/#example_Parse + + +``` 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 so : + +`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 **Notice**: This is a contrived (functioning) example meant strictly for API From 8a9326b22de6530c228989cc5c8a80d9008f65e0 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Mon, 27 Jan 2020 11:14:24 +0530 Subject: [PATCH 9/9] Update manual.md formatting nits --- docs/v2/manual.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 9f338cd..f3dea98 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1276,7 +1276,7 @@ func main() { ### Timestamp Flag -Using the timestamp flag is simple, You can look at time.Parse to get layout examples : https://golang.org/pkg/time/#example_Parse +Using the timestamp flag is simple. Please refer to [`time.Parse`](https://golang.org/pkg/time/#example_Parse) to get possible formats.