mirror of
https://github.com/syncthing/syncthing.git
synced 2026-03-31 04:31:23 -04:00
`syncthing cli` subcommand was using urfave/cli as the command parser. This PR replace it with kong, which the main command uses. Some help texts and error message format are changed. Other than that, all the command usage and logic remains unchanged. There's only one place which still uses urfave/cli, which is `syncthing cli config`, because it uses some magic to dynamically build commands from struct reflects. I used kong's `passthrough:""` tag to pass any argument following `syncthing cli config` to urfave/cli parser. This PR also fixes #9041 --------- Co-authored-by: Jakob Borg <jakob@kastelo.net>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
// Copyright (C) 2021 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
)
|
|
|
|
type fileCommand struct {
|
|
FolderID string `arg:""`
|
|
Path string `arg:""`
|
|
}
|
|
|
|
func (f *fileCommand) Run(ctx Context) error {
|
|
indexDumpOutput := indexDumpOutputWrapper(ctx.clientFactory)
|
|
|
|
query := make(url.Values)
|
|
query.Set("folder", f.FolderID)
|
|
query.Set("file", normalizePath(f.Path))
|
|
return indexDumpOutput("debug/file?" + query.Encode())
|
|
}
|
|
|
|
type profileCommand struct {
|
|
Type string `arg:"" help:"cpu | heap"`
|
|
}
|
|
|
|
func (p *profileCommand) Run(ctx Context) error {
|
|
switch t := p.Type; t {
|
|
case "cpu", "heap":
|
|
return saveToFile(fmt.Sprintf("debug/%vprof", p.Type), ctx.clientFactory)
|
|
default:
|
|
return fmt.Errorf("expected cpu or heap as argument, got %v", t)
|
|
}
|
|
}
|
|
|
|
type debugCommand struct {
|
|
File fileCommand `cmd:"" help:"Show information about a file (or directory/symlink)"`
|
|
Profile profileCommand `cmd:"" help:"Save a profile to help figuring out what Syncthing does"`
|
|
Index indexCommand `cmd:"" help:"Show information about the index (database)"`
|
|
}
|