Browse Source

Add folder add

tags/v1.0.0
dtluna 4 months ago
parent
commit
adb181cf57
4 changed files with 132 additions and 15 deletions
  1. 20
    15
      api/config.go
  2. 34
    0
      commands/folder.go
  3. 11
    0
      constants/constants.go
  4. 67
    0
      main.go

+ 20
- 15
api/config.go View File

@@ -89,21 +89,26 @@ Params: %v`,
}

type Folder struct {
ID string
Label string
Path string
Type string
Devices []FolderDevice
RescanIntervalS int
IgnorePerms bool
AutoNormalize bool
MinDiskFreePct int
Versioning VersioningInfo
Copiers int
Pullers int
Hashers int
Order string
IgnoreDelete bool
ID string
Label string
Path string
Type string
Devices []FolderDevice

RescanIntervalS int
FSWatcherEnabled bool
Order string
IgnorePerms bool
IgnoreDelete bool
MinDiskFreePct int
MinDiskFree string
Versioning VersioningInfo
AutoNormalize bool

Copiers int
Pullers int
Hashers int

ScanProgressIntervalS int
PullerSleepS int
PullerPauseS int

+ 34
- 0
commands/folder.go View File

@@ -2,6 +2,7 @@ package commands

import (
"fmt"
"path"

"git.dtluna.net/dtluna/syncthing-cli/api"
"git.dtluna.net/dtluna/syncthing-cli/config"
@@ -61,3 +62,36 @@ func FolderRemove(cfg *config.Config, folderID string) error {

return nil
}

func FolderAdd(
cfg *config.Config,
label, ID, folderPath, folderType, order string,
shareWith []string,
minDiskFreePct, rescanIntervalS int,
fsWatcherEnabled, ignorePerms, ignoreDelete bool,
) error {
if ID == "" {
ID = path.Base(folderPath)
}

folderDevices := []api.FolderDevice{}
for _, deviceID := range shareWith {
folderDevices = append(folderDevices, api.FolderDevice{DeviceID: deviceID})
}

newFolder := api.Folder{
ID: ID,
Label: label,
Path: folderPath,
Type: folderType,
Order: order,
IgnorePerms: ignorePerms,
Devices: folderDevices,
MinDiskFreePct: minDiskFreePct,
RescanIntervalS: rescanIntervalS,
FSWatcherEnabled: fsWatcherEnabled,
IgnoreDelete: ignoreDelete,
}
fmt.Println(newFolder)
return nil
}

+ 11
- 0
constants/constants.go View File

@@ -10,4 +10,15 @@ const (
CompressionMetadataOnly = "metadata"
CompressionAllData = "always"
CompressionOff = "never"

FolderTypeSendReceive = "sendreceive"
FolderTypeSendOnly = "sendonly"
FolderTypeReceiveOnly = "receiveonly"

FilePullOrderRandom = "random"
FilePullOrderAlphabetic = "alphabetic"
FilePullOrderSmallestFirst = "smallestFirst"
FilePullOrderLargestFirst = "largestFirst"
FilePullOrderOldestFirst = "oldestFirst"
FilePullOrderNewestFirst = "newestFirst"
)

+ 67
- 0
main.go View File

@@ -92,6 +92,58 @@ func main() {
folderList := folder.Command("list", "List folders.").Alias("l").Alias("ls")
folderStats := folder.Command("stats", "Show folder stats.").Alias("s").Alias("st")

folderAdd := folder.Command("add", "Add a new folder.").Alias("a")
folderAddLabel := folderAdd.Arg("label", "Label of the new folder.").Required().String()
folderAddPath := folderAdd.Arg("path", "Path to the new folder.").Required().ExistingDir()
folderAddID := folderAdd.Flag("id", "ID of the new folder.").Short('i').String()
folderAddType := folderAdd.Flag("type", "Type of the new folder.").
Default(constants.FolderTypeSendReceive).
Enum(
constants.FolderTypeSendReceive,
constants.FolderTypeSendOnly,
constants.FolderTypeReceiveOnly,
)
folderAddShareWith := folderAdd.Flag("share", "IDs of devices to share this folder with.").
Short('s').
Strings()
folderAddOrder := folderAdd.Flag("order", "File pull order.").
Short('o').
Default(constants.FilePullOrderRandom).
Enum(
constants.FilePullOrderRandom,
constants.FilePullOrderAlphabetic,
constants.FilePullOrderSmallestFirst,
constants.FilePullOrderLargestFirst,
constants.FilePullOrderOldestFirst,
constants.FilePullOrderNewestFirst,
)
folderAddMinDiskFreePct := folderAdd.Flag("min-free-space", "Minimum free disk space in percents.").
Short('m').
Int()
folderAddFSWatcherEnabled := folderAdd.Flag(
"fs-watcher-enabled",
"Watch for changes. Watching for changes discovers most changes without periodic scanning.",
).
Short('w').
Bool()
folderAddIgnorePerms := folderAdd.Flag(
"ignore-perms",
"File permission bits are ignored when looking for changes. Use on FAT file systems.",
).
Bool()
folderAddIgnoreDelete := folderAdd.Flag(
"ignore-delete",
"When set to true, this device will pretend not to see instructions to delete files from other devices.",
).
Bool()
folderAddRescanInterval := folderAdd.Flag(
"rescan-interval",
"Full folder rescan interval in seconds.",
).
Short('r').
Default("3600").
Int()

folderRemove := folder.Command("remove", "Remove a folder.").Alias("r").Alias("rm")
folderRemoveID := folderRemove.Arg("ID", "ID of the folder to remove.").Required().String()

@@ -140,6 +192,21 @@ func main() {
return commands.FolderList(cfg)
case folderStats.FullCommand():
return commands.FolderStats(cfg)
case folderAdd.FullCommand():
return commands.FolderAdd(
cfg,
*folderAddLabel,
*folderAddID,
*folderAddPath,
*folderAddType,
*folderAddOrder,
*folderAddShareWith,
*folderAddMinDiskFreePct,
*folderAddRescanInterval,
*folderAddFSWatcherEnabled,
*folderAddIgnorePerms,
*folderAddIgnoreDelete,
)
case folderRemove.FullCommand():
return commands.FolderRemove(cfg, *folderRemoveID)
case restart.FullCommand():

Loading…
Cancel
Save