mirror of
https://github.com/tailscale/tailscale.git
synced 2026-10-08 19:31:47 -04:00
Flatten the cmd/tailscale package hierarchy by extracting the jsonoutput package out of the cmd/tailscale/cli package. Updates #cleanup Change-Id: I92f80db75b0328e82f1596b6a42f6f6ef5a94bfa Signed-off-by: Simon Law <sfllaw@tailscale.com>
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package jsonoutput_test
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
|
|
"tailscale.com/cmd/tailscale/jsonoutput"
|
|
)
|
|
|
|
func ExampleFormat_JSONBool() {
|
|
var args struct {
|
|
format jsonoutput.Format
|
|
}
|
|
|
|
fs := flag.NewFlagSet("ExampleFormat", flag.ExitOnError)
|
|
fs.Var(&args.format, "format", `output format; empty (for human-readable), "json" or "json-line"`)
|
|
fs.Var(args.format.JSONBool(), "json", "output in JSON format")
|
|
|
|
fs.Parse([]string{"-json"})
|
|
fmt.Printf(`{format: %q, set: %t, version: %d}`, args.format, args.format.IsSet, args.format.Version)
|
|
// Output:
|
|
// {format: "json", set: true, version: 1}
|
|
}
|
|
|
|
func ExampleFormat_JSONSchemaVersion() {
|
|
var args struct {
|
|
format jsonoutput.Format
|
|
}
|
|
|
|
fs := flag.NewFlagSet("ExampleFormat", flag.ExitOnError)
|
|
fs.Var(&args.format, "format", `output format; empty (for human-readable), "json" or "json-line"`)
|
|
fs.Var(args.format.JSONSchemaVersion(), "json", "output in JSON format")
|
|
|
|
fs.Parse([]string{"-json=2", "-format=json-line"})
|
|
fmt.Printf(`{format: %q, set: %t, version: %d}`, args.format, args.format.IsSet, args.format.Version)
|
|
// Output:
|
|
// {format: "json-line", set: true, version: 2}
|
|
}
|