Skip to content

Commit

Permalink
add json config support
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Nov 29, 2024
1 parent 9841d64 commit 2755d0e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 31 deletions.
44 changes: 29 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,27 @@ Run `chkbit PATH` to verify only.
```
Usage: chkbit [<paths> ...] [flags]
Ensures the safety of your files by verifying that their data integrity remains
intact over time, especially during transfers and backups.
For help tips run "chkbit -H" or go to
https://github.com/laktak/chkbit
Arguments:
[<paths> ...] directories to check
Flags:
-h, --help Show context-sensitive help.
-H, --tips Show tips.
-c, --check check mode: chkbit will verify files in readonly
mode (default mode)
-u, --update update mode: add and update indices
-a, --add-only add mode: only add new and modified files,
do not check existing (quicker)
-i, --show-ignored-only show-ignored mode: only show ignored files
-m, --show-missing show missing files/directories
-d, --include-dot include dot files
-m, --[no-]show-missing show missing files/directories
-d, --[no-]include-dot include dot files
-S, --[no-]skip-symlinks do not follow symlinks
-R, --[no-]no-recurse do not recurse into subdirectories
-D, --[no-]no-dir-in-index do not track directories in the index
--force force update of damaged items (advanced usage
only)
-S, --skip-symlinks do not follow symlinks
-R, --no-recurse do not recurse into subdirectories
-D, --no-dir-in-index do not track directories in the index
-l, --log-file=STRING write to a logfile if specified
--log-verbose verbose logging
--[no-]log-verbose verbose logging
--algo="blake3" hash algorithm: md5, sha512, blake3 (default:
blake3)
--index-name=".chkbit" filename where chkbit stores its hashes,
Expand All @@ -112,10 +112,18 @@ Flags:
filename that chkbit reads its ignore list from,
needs to start with '.' (default: .chkbitignore)
-w, --workers=5 number of workers to use (default: 5)
--plain show plain status instead of being fancy
-q, --quiet quiet, don't show progress/information
-v, --verbose verbose output
--[no-]plain show plain status instead of being fancy
-q, --[no-]quiet quiet, don't show progress/information
-v, --[no-]verbose verbose output
-V, --version show version information
mode
-c, --check check mode: chkbit will verify files in readonly
mode (default mode)
-u, --update update mode: add and update indices
-a, --add-only add mode: only add new and modified files, do not
check existing (quicker)
-i, --show-ignored-only show-ignored mode: only show ignored files
```

```
Expand All @@ -142,6 +150,12 @@ Status codes:
del: file/directory removed
ign: ignored (see .chkbitignore)
EXC: exception/panic
Configuration file (json):
- location /home/spark/.config/chkbit/config.json
- key names are the option names with '-' replaced by '_'
- for example --include-dot is written as:
{ "include_dot": true }
```

chkbit is set to use only 5 workers by default so it will not slow your system to a crawl. You can specify a higher number to make it a lot faster if the IO throughput can also keep up.
Expand Down
6 changes: 6 additions & 0 deletions cmd/chkbit/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ Status codes:
del: file/directory removed
ign: ignored (see .chkbitignore)
EXC: exception/panic
Configuration file (json):
- location <config-file>
- key names are the option names with '-' replaced by '_'
- for example --include-dot is written as:
{ "include_dot": true }
`
36 changes: 22 additions & 14 deletions cmd/chkbit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"log"
"os"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -44,25 +45,25 @@ var (
var cli struct {
Paths []string `arg:"" optional:"" name:"paths" help:"directories to check"`
Tips bool `short:"H" help:"Show tips."`
Check bool `short:"c" help:"check mode: chkbit will verify files in readonly mode (default mode)"`
Update bool `short:"u" help:"update mode: add and update indices"`
AddOnly bool `short:"a" help:"add mode: only add new and modified files, do not check existing (quicker)"`
ShowIgnoredOnly bool `short:"i" help:"show-ignored mode: only show ignored files"`
ShowMissing bool `short:"m" help:"show missing files/directories"`
IncludeDot bool `short:"d" help:"include dot files"`
Check bool `short:"c" help:"check mode: chkbit will verify files in readonly mode (default mode)" xor:"mode" group:"mode"`
Update bool `short:"u" help:"update mode: add and update indices" xor:"mode" group:"mode"`
AddOnly bool `short:"a" help:"add mode: only add new and modified files, do not check existing (quicker)" xor:"mode" group:"mode"`
ShowIgnoredOnly bool `short:"i" help:"show-ignored mode: only show ignored files" xor:"mode" group:"mode"`
ShowMissing bool `short:"m" help:"show missing files/directories" negatable:""`
IncludeDot bool `short:"d" help:"include dot files" negatable:""`
SkipSymlinks bool `short:"S" help:"do not follow symlinks" negatable:""`
NoRecurse bool `short:"R" help:"do not recurse into subdirectories" negatable:""`
NoDirInIndex bool `short:"D" help:"do not track directories in the index" negatable:""`
Force bool `help:"force update of damaged items (advanced usage only)"`
SkipSymlinks bool `short:"S" help:"do not follow symlinks"`
NoRecurse bool `short:"R" help:"do not recurse into subdirectories"`
NoDirInIndex bool `short:"D" help:"do not track directories in the index"`
LogFile string `short:"l" help:"write to a logfile if specified"`
LogVerbose bool `help:"verbose logging"`
LogVerbose bool `help:"verbose logging" negatable:""`
Algo string `default:"blake3" help:"hash algorithm: md5, sha512, blake3 (default: blake3)"`
IndexName string `default:".chkbit" help:"filename where chkbit stores its hashes, needs to start with '.' (default: .chkbit)"`
IgnoreName string `default:".chkbitignore" help:"filename that chkbit reads its ignore list from, needs to start with '.' (default: .chkbitignore)"`
Workers int `short:"w" default:"5" help:"number of workers to use (default: 5)"`
Plain bool `help:"show plain status instead of being fancy"`
Quiet bool `short:"q" help:"quiet, don't show progress/information"`
Verbose bool `short:"v" help:"verbose output"`
Plain bool `help:"show plain status instead of being fancy" negatable:""`
Quiet bool `short:"q" help:"quiet, don't show progress/information" negatable:""`
Verbose bool `short:"v" help:"verbose output" negatable:""`
Version bool `short:"V" help:"show version information"`
}

Expand Down Expand Up @@ -285,14 +286,21 @@ func (m *Main) run() {
os.Args = append(os.Args, "--help")
}

var configPath = "chkbit-config.json"
configRoot, err := os.UserConfigDir()
if err == nil {
configPath = filepath.Join(configRoot, "chkbit/config.json")
}

kong.Parse(&cli,
kong.Name("chkbit"),
kong.Description(headerHelp),
kong.UsageOnError(),
kong.Configuration(kong.JSON, configPath),
)

if cli.Tips {
fmt.Println(helpTips)
fmt.Println(strings.ReplaceAll(helpTips, "<config-file>", configPath))
os.Exit(0)
}

Expand Down
13 changes: 11 additions & 2 deletions scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ set -e
script_dir=$(dirname "$(realpath "$0")")
cd $script_dir/..

# prep
echo "# test module"
go test -v .
echo "# test util"
go test -v ./cmd/chkbit/util -count=1

echo "# prep files"
$script_dir/build

go test -v ./cmd/chkbit/util -count=1
echo "# test files"
if [[ -f ~/.config/chkbit/config.json ]]; then
echo 'error: unable to test with config file preset'
exit 1
fi
go test -v ./scripts -count=1

0 comments on commit 2755d0e

Please sign in to comment.