summaryrefslogtreecommitdiffhomepage
path: root/cmd/tailscaled/flag.go
blob: 357210a29c426223be76c656021d1fd236a6a3cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause

package main

import "strconv"

// boolFlag is a flag.Value that tracks whether it was ever set.
type boolFlag struct {
	set bool
	v   bool
}

func (b *boolFlag) String() string {
	if b == nil || !b.set {
		return "unset"
	}
	return strconv.FormatBool(b.v)
}

func (b *boolFlag) Set(s string) error {
	v, err := strconv.ParseBool(s)
	if err != nil {
		return err
	}
	b.v = v
	b.set = true
	return nil
}

func (b *boolFlag) IsBoolFlag() bool { return true }