github.com/keybase/client/go@v0.0.0-20240520164431-4f512a4c85a3/client/cmd_simplefs_index_progress.go (about)

     1  // Copyright 2020 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  	"time"
    10  
    11  	"github.com/keybase/cli"
    12  	"github.com/keybase/client/go/libcmdline"
    13  	"github.com/keybase/client/go/libkb"
    14  	"github.com/keybase/client/go/protocol/keybase1"
    15  )
    16  
    17  // CmdSimpleFSIndexProgress is the 'fs index-progress' command.
    18  type CmdSimpleFSIndexProgress struct {
    19  	libkb.Contextified
    20  }
    21  
    22  // NewCmdSimpleFSIndexProgress creates a new cli.Command.
    23  func NewCmdSimpleFSIndexProgress(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    24  	return cli.Command{
    25  		Name:  "index-progress",
    26  		Usage: "[disabled] print the current progress of the indexer",
    27  		Action: func(c *cli.Context) {
    28  			cl.ChooseCommand(&CmdSimpleFSIndexProgress{
    29  				Contextified: libkb.NewContextified(g)}, "index-progress", c)
    30  			cl.SetNoStandalone()
    31  		},
    32  	}
    33  }
    34  
    35  func printIndexProgress(
    36  	ui libkb.TerminalUI, p keybase1.IndexProgressRecord) {
    37  	ui.Printf("\t%s/%s (%.2f%%)\n",
    38  		humanizeBytes(p.BytesSoFar, false),
    39  		humanizeBytes(p.BytesTotal, false),
    40  		100*float64(p.BytesSoFar)/float64(p.BytesTotal))
    41  
    42  	if p.EndEstimate > 0 {
    43  		timeRemaining := time.Until(keybase1.FromTime(p.EndEstimate))
    44  		ui.Printf("\tEstimated time remaining: %s\n",
    45  			timeRemaining.Round(1*time.Second))
    46  	}
    47  }
    48  
    49  // Run runs the command in client/server mode.
    50  func (c *CmdSimpleFSIndexProgress) Run() error {
    51  	cli, err := GetSimpleFSClient(c.G())
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	p, err := cli.SimpleFSGetIndexProgress(context.TODO())
    57  	if err != nil {
    58  		return err
    59  	}
    60  
    61  	ui := c.G().UI.GetTerminalUI()
    62  	if p.OverallProgress.BytesTotal == 0 {
    63  		ui.Printf("No indexing in progress\n")
    64  		return nil
    65  	}
    66  
    67  	ui.Printf("Overall index progress:\n")
    68  	printIndexProgress(ui, p.OverallProgress)
    69  	if p.CurrFolder.Name != "" {
    70  		ui.Printf("\nCurrent index progress (%s):\n", p.CurrFolder)
    71  		printIndexProgress(ui, p.CurrProgress)
    72  	}
    73  
    74  	if len(p.FoldersLeft) > 0 {
    75  		ui.Printf("\nFolders waiting to be indexed:\n")
    76  		for _, f := range p.FoldersLeft {
    77  			ui.Printf("\t%s\n", f)
    78  		}
    79  	}
    80  	return nil
    81  }
    82  
    83  // ParseArgv gets the optional flags and the query.
    84  func (c *CmdSimpleFSIndexProgress) ParseArgv(ctx *cli.Context) error {
    85  	if len(ctx.Args()) != 0 {
    86  		return fmt.Errorf("wrong number of arguments")
    87  	}
    88  
    89  	return nil
    90  }
    91  
    92  // GetUsage says what this command needs to operate.
    93  func (c *CmdSimpleFSIndexProgress) GetUsage() libkb.Usage {
    94  	return libkb.Usage{
    95  		Config:    true,
    96  		KbKeyring: true,
    97  		API:       true,
    98  	}
    99  }