github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/client/cmd_simplefs_set_debug_level.go (about)

     1  // Copyright 2019 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package client
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  	"strconv"
    10  
    11  	"github.com/keybase/cli"
    12  	"github.com/keybase/client/go/libcmdline"
    13  	"github.com/keybase/client/go/libkb"
    14  )
    15  
    16  // CmdSimpleFSSetDebugLevel is the 'fs set-debug-level' command.
    17  type CmdSimpleFSSetDebugLevel struct {
    18  	libkb.Contextified
    19  	level string
    20  }
    21  
    22  // NewCmdSimpleFSSetDebugLevel creates a new cli.Command.
    23  func NewCmdSimpleFSSetDebugLevel(
    24  	cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    25  	return cli.Command{
    26  		Name:         "set-debug-level",
    27  		ArgumentHelp: "<integer_level>",
    28  		Usage:        "Changes the amount of debug logging done by the file system",
    29  		Action: func(c *cli.Context) {
    30  			cl.ChooseCommand(&CmdSimpleFSSetDebugLevel{
    31  				Contextified: libkb.NewContextified(g)}, "set-debug-level", c)
    32  			cl.SetNoStandalone()
    33  		},
    34  	}
    35  }
    36  
    37  // Run runs the command in client/server mode.
    38  func (c *CmdSimpleFSSetDebugLevel) Run() error {
    39  	if c.level > libkb.VLog0String {
    40  		ui := c.G().UI.GetTerminalUI()
    41  		ui.Printf("WARNING: this will make file and directory names visible in your logs.\n")
    42  		ui.Printf("If you send the logs to Keybase for debugging, those names will be\n")
    43  		ui.Printf("visible to Keybase employees as well.  File contents will remain private.\n")
    44  	}
    45  
    46  	cli, err := GetSimpleFSClient(c.G())
    47  	if err != nil {
    48  		return err
    49  	}
    50  
    51  	return cli.SimpleFSSetDebugLevel(context.TODO(), c.level)
    52  }
    53  
    54  // ParseArgv gets and validates the level string.
    55  func (c *CmdSimpleFSSetDebugLevel) ParseArgv(ctx *cli.Context) error {
    56  	if len(ctx.Args()) != 1 {
    57  		return fmt.Errorf("wrong number of arguments")
    58  	}
    59  
    60  	level, err := strconv.Atoi(ctx.Args()[0])
    61  	if err != nil {
    62  		return fmt.Errorf("The log level must be an integer")
    63  	}
    64  	c.level = libkb.VDebugLevel(level).String()
    65  	return nil
    66  }
    67  
    68  // GetUsage says what this command needs to operate.
    69  func (c *CmdSimpleFSSetDebugLevel) GetUsage() libkb.Usage {
    70  	return libkb.Usage{
    71  		Config:    true,
    72  		KbKeyring: true,
    73  		API:       true,
    74  	}
    75  }