Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration variable #1

Merged
merged 4 commits into from
Mar 16, 2017
Merged

Duration variable #1

merged 4 commits into from
Mar 16, 2017

Conversation

timjchin
Copy link
Owner

This PR adds a new time.Duration variable.

In JSON and TOML, these need to be string values:

Most basic example:

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/timjchin/unpuzzled"
)

func main() {
	var duration time.Duration
	app := unpuzzled.NewApp()
	app.Command = &unpuzzled.Command{
		Name:  "main",
		Usage: "An example application that uses an unpuzzled.DurationVariable.",
		Variables: []unpuzzled.Variable{
			&unpuzzled.DurationVariable{
				Name:        "test-duration",
				Description: "An example time.Duration variable.",
				Destination: &duration,
				Default:     time.Second,
			},
		},
		Action: func() {
			fmt.Println("Duration has been parsed!", duration)
		},
	}

	app.Run(os.Args)
}

If a config variable is added, the durations should be strings:

TOML:

[main]
test-duration="15s"

JSON:

{
    "main": {
        "test-duration": "15s"
    }
}

@timjchin timjchin merged commit e17b3df into master Mar 16, 2017
@timjchin timjchin deleted the feature/duration-variable branch March 16, 2017 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant