mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-09 01:34:39 +00:00

This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package cli
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
|
|
"github.com/peterbourgon/ff/v3/ffcli"
|
|
"tailscale.com/ipn"
|
|
)
|
|
|
|
var downCmd = &ffcli.Command{
|
|
Name: "down",
|
|
ShortUsage: "down",
|
|
ShortHelp: "Disconnect from Tailscale",
|
|
|
|
Exec: runDown,
|
|
FlagSet: newDownFlagSet(),
|
|
}
|
|
|
|
var downArgs struct {
|
|
acceptedRisks string
|
|
}
|
|
|
|
func newDownFlagSet() *flag.FlagSet {
|
|
downf := newFlagSet("down")
|
|
registerAcceptRiskFlag(downf, &downArgs.acceptedRisks)
|
|
return downf
|
|
}
|
|
|
|
func runDown(ctx context.Context, args []string) error {
|
|
if len(args) > 0 {
|
|
return fmt.Errorf("too many non-flag arguments: %q", args)
|
|
}
|
|
|
|
if isSSHOverTailscale() {
|
|
if err := presentRiskToUser(riskLoseSSH, `You are connected over Tailscale; this action will disable Tailscale and result in your session disconnecting.`, downArgs.acceptedRisks); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
st, err := localClient.Status(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("error fetching current status: %w", err)
|
|
}
|
|
if st.BackendState == "Stopped" {
|
|
fmt.Fprintf(Stderr, "Tailscale was already stopped.\n")
|
|
return nil
|
|
}
|
|
_, err = localClient.EditPrefs(ctx, &ipn.MaskedPrefs{
|
|
Prefs: ipn.Prefs{
|
|
WantRunning: false,
|
|
},
|
|
WantRunningSet: true,
|
|
})
|
|
return err
|
|
}
|