Skip to content

Commit

Permalink
allow passing path to restic as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
emuell committed Oct 10, 2023
1 parent 41bdebb commit 5062db2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ The UI is navigatable via keyboard shortcuts. To change the focus area, hit `Tab
## System Requirements

#### All platforms
- Install [restic](https://github.com/restic/restic/releases/) and *make sure it is included in your $PATH*.
- Install [restic](https://github.com/restic/restic/releases/) and *make sure it is included in your $PATH* or
pass the path to the restic executable *as argument*: `Restic-Browser[.exe] --restic="PATH/TO/restic[.exe]"`.

#### Windows:
- Windows 10 or later with [WebView2 Runtime](https://developer.microsoft.com/de-de/microsoft-edge/webview2/#download-section)
Expand Down
6 changes: 3 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type ResticBrowserApp struct {
snapshots map[string]*restic.Snapshot
}

func NewResticBrowser() *ResticBrowserApp {
program, err := restic.NewRestic()
func NewResticBrowser(resticPath *string) *ResticBrowserApp {
program, err := restic.NewRestic(resticPath)
if err != nil {
// continue without a valid restic instance
fmt.Print(err.Error() + "\n")
Expand Down Expand Up @@ -91,7 +91,7 @@ func (r *ResticBrowserApp) DomReady(ctx context.Context) {
// warn about missing restic program: this is the first time we can show a dialog
if r.restic == nil {
message := fmt.Sprintf(
"Failed to find a restic program in your $PATH: %s\n\n", r.resticError.Error()) +
"Failed to find restic program: %s\n\n", r.resticError.Error()) +
"Please select your installed restic binary manually in the following dialog."
r.showWarning("Restic Binary Missing", message)
selectFileOptions := runtime.OpenDialogOptions{
Expand Down
26 changes: 19 additions & 7 deletions backend/restic/restic.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,25 @@ func resticVersionNumber(resticProgram *program.Program) ([3]int, error) {
}

// NewRestic creates a new Restic struct
func NewRestic() (restic *Restic, err error) {

// Find restic executable in PATH
programName := ResticProgramName()
resticProgram := program.Find(programName, "Restic")
if resticProgram == nil {
return nil, fmt.Errorf("unable to find '%s'", programName)
func NewRestic(resticPath* string) (restic *Restic, err error) {
// Get restic from args or find restic executable in PATH
var resticProgram *program.Program;
if resticPath != nil && len(*resticPath) > 0 {
_, err := os.Stat(*resticPath)
if err != nil {
return nil, err
}
resticProgram = &program.Program{
Name: "Restic",
Filename: filepath.Base(*resticPath),
Path: *resticPath,
}
} else {
programName := ResticProgramName()
resticProgram = program.Find(programName, "Restic")
if resticProgram == nil {
return nil, fmt.Errorf("unable to find '%s' in $PATH", programName)
}
}

// Get the version
Expand Down
8 changes: 4 additions & 4 deletions backend/restic/restic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestResticRepoPath(t *testing.T) {

// test if restic program can be resolved and if it can be launched to query version info
func TestResticProgram(t *testing.T) {
restic, err := NewRestic()
restic, err := NewRestic(nil)
if err != nil {
t.Fatal("failed to resolve restic binary", err)
}
Expand All @@ -66,7 +66,7 @@ func TestResticProgram(t *testing.T) {
// test opening repo and fetching snapshots
func TestResticSnapshots(t *testing.T) {
repoPath := getTestRepoPath()
restic, err := NewRestic()
restic, err := NewRestic(nil)
if err != nil {
t.Fatal("failed to resolve restic binary", err)
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestResticSnapshots(t *testing.T) {
// test opening repo and fetching files
func TestResticFiles(t *testing.T) {
repoPath := getTestRepoPath()
restic, err := NewRestic()
restic, err := NewRestic(nil)
if err != nil {
t.Fatal("failed to resolve restic binary", err)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestResticFiles(t *testing.T) {

func TestResticFileDump(t *testing.T) {
repoPath := getTestRepoPath()
restic, err := NewRestic()
restic, err := NewRestic(nil)
if err != nil {
t.Fatal("failed to resolve restic binary", err)
}
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"embed"
"flag"

"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
Expand All @@ -11,8 +12,12 @@ import (
var assets embed.FS

func main() {
// parse command line args
resticPath := flag.String("restic", "", "Optional path to the restic binary");
flag.Parse()

// Create an instance of the restic app
app := NewResticBrowser()
app := NewResticBrowser(resticPath)

// Create wails application with options and bind the app to the frontend
err := wails.Run(&options.App{
Expand Down

0 comments on commit 5062db2

Please sign in to comment.