Pārlūkot izejas kodu

Add folder list

tags/v1.0.0
dtluna pirms 4 mēnešiem
vecāks
revīzija
72f1e26890
6 mainītis faili ar 115 papildinājumiem un 21 dzēšanām
  1. 41
    20
      api/config.go
  2. 2
    1
      commands/device.go
  3. 21
    0
      commands/folder.go
  4. 23
    0
      format/device.go
  5. 23
    0
      format/folder.go
  6. 5
    0
      main.go

+ 41
- 20
api/config.go Parādīt failu

@@ -18,11 +18,11 @@ func indent(s string, depth int) string {
}

func indentStringSlice(slice []string, depth int) string {
sep := strings.Repeat(" ", depth)
if len(slice) == 0 {
return "None"
}

sep := strings.Repeat(" ", depth)
lines := []string{}

for i, el := range slice {
@@ -39,9 +39,38 @@ func (fd FolderDevice) String() string {
return fmt.Sprint("ID: ", fd.DeviceID)
}

func indentFolderDevices(fds []FolderDevice, depth int) string {
if len(fds) == 0 {
return "None"
}

sep := strings.Repeat(" ", depth)
lines := []string{}

for i, el := range fds {
line := strings.ReplaceAll(fmt.Sprintf("%v. %s", i+1, el), "\n", "\n"+sep)
lines = append(lines, line)
}
return "\n" + strings.Join(lines, "\n")
}

type VersioningInfoParams map[string]interface{}

func (vip VersioningInfoParams) String() string {
if len(vip) == 0 {
return "None"
}

slice := []string{}
for key, value := range vip {
slice = append(slice, fmt.Sprintf("%v: %v", key, value))
}
return strings.Join(slice, "\n")
}

type VersioningInfo struct {
Type string
Params map[string]interface{}
Params VersioningInfoParams
}

func (vi VersioningInfo) String() string {
@@ -49,7 +78,7 @@ func (vi VersioningInfo) String() string {
`Type: %v
Params: %v`,
vi.Type,
vi.Params,
indent(vi.Params.String(), 2),
)
}

@@ -80,6 +109,13 @@ type Folder struct {
}

func (f Folder) String() string {
var viString string
if f.Versioning.Type == "" {
viString = "None"
} else {
viString = indent(f.Versioning.String(), 2)
}

return fmt.Sprintf(
`ID: %v
Label: %v
@@ -91,8 +127,8 @@ Versioning: %v`,
f.Label,
f.Path,
f.Type,
f.Devices,
f.Versioning,
indentFolderDevices(f.Devices, 2),
viString,
)
}

@@ -122,21 +158,6 @@ Introducer: %v`,
)
}

func IndentDevices(ds []Device, depth int) string {
sep := strings.Repeat(" ", depth)
if len(ds) == 0 {
return "None"
}

lines := []string{}

for i, el := range ds {
line := strings.ReplaceAll(fmt.Sprintf("%v. %s", i+1, el), "\n", "\n"+sep)
lines = append(lines, line)
}
return "\n" + strings.Join(lines, "\n")
}

type GUIConfig struct {
Enabled bool
Address string

+ 2
- 1
commands/device.go Parādīt failu

@@ -5,6 +5,7 @@ import (

"git.dtluna.net/dtluna/syncthing-cli/api"
"git.dtluna.net/dtluna/syncthing-cli/config"
"git.dtluna.net/dtluna/syncthing-cli/format"

"github.com/hashicorp/errwrap"
)
@@ -15,7 +16,7 @@ func DeviceList(cfg *config.Config) error {
return errwrap.Wrapf("getting config: {{err}}", err)
}

fmt.Println(api.IndentDevices(stconfig.Devices, 2))
fmt.Println(format.IndentDevices(stconfig.Devices, 2))
return nil
}


+ 21
- 0
commands/folder.go Parādīt failu

@@ -0,0 +1,21 @@
package commands

import (
"fmt"

"git.dtluna.net/dtluna/syncthing-cli/api"
"git.dtluna.net/dtluna/syncthing-cli/config"
"git.dtluna.net/dtluna/syncthing-cli/format"

"github.com/hashicorp/errwrap"
)

func FolderList(cfg *config.Config) error {
stconfig, err := api.GetConfig(cfg)
if err != nil {
return errwrap.Wrapf("getting config: {{err}}", err)
}

fmt.Println(format.IndentFolders(stconfig.Folders, 2))
return nil
}

+ 23
- 0
format/device.go Parādīt failu

@@ -0,0 +1,23 @@
package format

import (
"fmt"
"strings"

"git.dtluna.net/dtluna/syncthing-cli/api"
)

func IndentDevices(ds []api.Device, depth int) string {
if len(ds) == 0 {
return "None"
}

sep := strings.Repeat(" ", depth)
lines := []string{}

for i, el := range ds {
line := strings.ReplaceAll(fmt.Sprintf("%v. %s", i+1, el), "\n", "\n"+sep)
lines = append(lines, line)
}
return "\n" + strings.Join(lines, "\n")
}

+ 23
- 0
format/folder.go Parādīt failu

@@ -0,0 +1,23 @@
package format

import (
"fmt"
"strings"

"git.dtluna.net/dtluna/syncthing-cli/api"
)

func IndentFolders(ds []api.Folder, depth int) string {
if len(ds) == 0 {
return "None"
}

sep := strings.Repeat(" ", depth)
lines := []string{}

for i, el := range ds {
line := strings.ReplaceAll(fmt.Sprintf("%v. %s", i+1, el), "\n", "\n"+sep)
lines = append(lines, line)
}
return "\n" + strings.Join(lines, "\n")
}

+ 5
- 0
main.go Parādīt failu

@@ -67,6 +67,9 @@ func main() {
deviceList := device.Command("list", "List devices.").Alias("l").Alias("ls")
deviceStats := device.Command("stats", "Show device stats.").Alias("s").Alias("st")

folder := app.Command("folder", "Work with folders.").Alias("f").Alias("fl").Alias("fold")
folderList := folder.Command("list", "List folders.").Alias("l").Alias("ls")

commandName := kingpin.MustParse(app.Parse(os.Args[1:]))

cfg, err := config.Parse(*configPath)
@@ -85,6 +88,8 @@ func main() {
return commands.DeviceList(cfg)
case deviceStats.FullCommand():
return commands.DeviceStats(cfg)
case folderList.FullCommand():
return commands.FolderList(cfg)
}
return nil
}()

Notiek ielāde…
Atcelt
Saglabāt