testing/gimmeproj: add option to output list
@@ -32,6 +32,7 @@ import (
var (
metaProject = flag.String("project", "", "Meta-project that manages the pool.")
+ format = flag.String("output", "", "Output format for selected operations. Options include: list")
datastore *ds.Client
version = "dev"
@@ -102,6 +103,7 @@ func submain() error {
usage := errors.New(`
Usage:
gimmeproj -project=[meta project ID] command
+ gimmeproj -project=[meta project ID] -output=list status
Commands:
lease [duration] Leases a project for a given duration. Prints the project ID to stdout.
@@ -111,7 +113,7 @@ Commands:
Administrative commands:
pool-add [project ID] Adds a project to the pool.
pool-rm [project ID] Removes a project from the pool.
- status Displays the current status of the meta project.
+ status Displays the current status of the meta project. Respects -output.
`)
if flag.Arg(0) == "version" {
@@ -230,14 +232,23 @@ func done(ctx context.Context, projectID string) error {
func status(ctx context.Context) error {
return withPool(ctx, func(pool *Pool) error {
+ if *format == "" {
fmt.Printf("%-8s %s\n", "LEASE", "PROJECT")
+ }
for _, proj := range pool.Projects {
exp := ""
if !proj.Expired() {
secs := proj.LeaseExpiry.Sub(time.Now()) / time.Second * time.Second
exp = secs.String()
}
+ switch *format {
+ case "":
fmt.Printf("%-8s %s\n", exp, proj.ID)
+ case "list":
+ fmt.Printf("%s\n", proj.ID)
+ default:
+ return errors.New("output may be '', 'list'")
+ }
}
return nil
})
