Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
343f355
feat: add terminal instance instead of global term package
creativeprojects Apr 5, 2026
a21a1d6
Refactor terminal handling in wrapper and tests
creativeprojects Apr 5, 2026
248458a
feat: refactor terminal handling and remove deprecated functions
creativeprojects Apr 5, 2026
80ffa82
refactor: update terminal handling to use new terminal instance and r…
creativeprojects Apr 5, 2026
577c442
fix: update nilReader to return io.EOF and improve error handling in …
creativeprojects Apr 5, 2026
561008a
refactor: update terminal handling to use atomic pointers and improve…
creativeprojects Apr 5, 2026
9a31617
refactor: remove TestAsyncFileWriterFilePerm test case to streamline …
creativeprojects Apr 5, 2026
43e324d
refactor: update codecov configuration and remove unused shell utilit…
creativeprojects Apr 5, 2026
f9aaed5
test: add TestContextWithTerminal to validate terminal assignment
creativeprojects Apr 5, 2026
28366c6
refactor: enhance terminal handling with new options and improve outp…
creativeprojects Apr 6, 2026
7fc967e
refactor: replace AsyncFileWriter with new write package and improve …
creativeprojects Apr 6, 2026
c8abab1
refactor: change flusher channel type to error and update flush handling
creativeprojects Apr 6, 2026
66c0430
refactor: enhance file handling with keep open timeout and add stats …
creativeprojects Apr 7, 2026
890b393
refactor: improve async writer with flusher state management and add …
creativeprojects Apr 7, 2026
2816684
refactor: implement Close method for Append and enhance file handling…
creativeprojects Apr 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ build-windows: prepare_build ## Build the binary for Windows

build-all: build-mac build-linux build-pi build-windows ## Build the binary for all platforms

test: prepare_test ## Run unit tests
test: $(GOBIN)/gotestsum prepare_test ## Run unit tests
@echo "[*] $@"
$(GOTEST) $(TESTS)
$(GOBIN)/gotestsum $(TESTS)

test-ci: $(GOBIN)/gotestsum prepare_test ## Run unit tests with coverage (for CI)
@echo "[*] $@"
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ignore:
- priority/check/
- util/test_executable/
- term/remote.go
- term/test/
- deprecation.go
- logger.go
- systemd.go
Expand Down
43 changes: 22 additions & 21 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/creativeprojects/resticprofile/constants"
"github.com/creativeprojects/resticprofile/platform"
"github.com/creativeprojects/resticprofile/remote"
"github.com/creativeprojects/resticprofile/term"
"github.com/creativeprojects/resticprofile/util/ansi"
"github.com/creativeprojects/resticprofile/win"
"github.com/distatus/battery"
)
Expand Down Expand Up @@ -190,11 +190,11 @@ func getOwnCommands() []ownCommand {
}
}

func panicCommand(_ io.Writer, _ commandContext) error {
func panicCommand(_ commandContext) error {
panic("you asked for it")
}

func completeCommand(output io.Writer, ctx commandContext) error {
func completeCommand(ctx commandContext) error {
args := ctx.request.arguments
requester := "unknown"
requesterVersion := 0
Expand Down Expand Up @@ -226,13 +226,13 @@ func completeCommand(output io.Writer, ctx commandContext) error {
completions := NewCompleter(ctx.ownCommands.All(), DefaultFlagsLoader, includeDescription).Complete(args)
if len(completions) > 0 {
for _, completion := range completions {
fmt.Fprintln(output, completion)
ctx.terminal.Println(completion)
}
}
return nil
}

func showProfileOrGroup(output io.Writer, ctx commandContext) error {
func showProfileOrGroup(ctx commandContext) error {
c := ctx.config
flags := ctx.flags

Expand Down Expand Up @@ -270,21 +270,21 @@ func showProfileOrGroup(output io.Writer, ctx commandContext) error {
}

// Show global
err = config.ShowStruct(output, global, constants.SectionConfigurationGlobal)
err = config.ShowStruct(ctx.terminal, global, constants.SectionConfigurationGlobal)
if err != nil {
clog.Errorf("cannot show global section: %s", err.Error())
}
_, _ = fmt.Fprintln(output)
_, _ = ctx.terminal.Println()

// Show profile or group
err = config.ShowStruct(output, profileOrGroup, profileOrGroup.Kind()+" "+flags.name)
err = config.ShowStruct(ctx.terminal, profileOrGroup, profileOrGroup.Kind()+" "+flags.name)
if err != nil {
clog.Errorf("cannot show profile or group '%s': %s", flags.name, err.Error())
}
_, _ = fmt.Fprintln(output)
_, _ = ctx.terminal.Println()

// Show schedules
showSchedules(output, slices.Collect(maps.Values(profileOrGroup.Schedules())))
showSchedules(ctx.terminal, slices.Collect(maps.Values(profileOrGroup.Schedules())))

if profile, ok := profileOrGroup.(*config.Profile); ok {
// Show deprecation notice
Expand All @@ -309,7 +309,7 @@ func showSchedules(output io.Writer, schedules []*config.Schedule) {
}

// randomKey simply display a base64'd random key to the console
func randomKey(output io.Writer, ctx commandContext) error {
func randomKey(ctx commandContext) error {
var err error
flags := ctx.flags
size := uint64(1024)
Expand All @@ -329,19 +329,20 @@ func randomKey(output io.Writer, ctx commandContext) error {
if err != nil {
return err
}
encoder := base64.NewEncoder(base64.StdEncoding, output)
encoder := base64.NewEncoder(base64.StdEncoding, ctx.terminal)
_, err = encoder.Write(buffer)
encoder.Close()
fmt.Fprintln(output, "")
ctx.terminal.Println()
return err
}

func testElevationCommand(_ io.Writer, ctx commandContext) error {
func testElevationCommand(ctx commandContext) error {
if ctx.flags.isChild {
client := remote.NewClient(ctx.flags.parentPort)
term.Print("first line", "\n")
term.Println("second", "one")
term.Printf("value = %d\n", 11)
ctx.terminal.Print("simple line", "\n")
ctx.terminal.Printf("value = %d\n", 11)
ctx.terminal.Println(ansi.Bold("in bold"))
clog.Info("log content")
err := client.Done()
if err != nil {
return err
Expand Down Expand Up @@ -395,7 +396,7 @@ func elevated() error {
return nil
}

func batteryCommand(stdout io.Writer, _ commandContext) error {
func batteryCommand(ctx commandContext) error {
all, err := batt.Batteries()
if err != nil {
if errors.Is(err, battery.ErrFatal{}) {
Expand All @@ -407,13 +408,13 @@ func batteryCommand(stdout io.Writer, _ commandContext) error {
clog.Info("no battery detected")
return nil
}
fmt.Fprintln(stdout, "")
w := tabwriter.NewWriter(stdout, 2, 2, 2, ' ', tabwriter.AlignRight)
ctx.terminal.Println()
w := tabwriter.NewWriter(ctx.terminal, 2, 2, 2, ' ', tabwriter.AlignRight)
fmt.Fprintf(w, "Battery\tStatus\tCurrent capacity\tFull capacity\tDesign Capacity\tCharge Rate\tVoltage\t\n")
for index, batt := range all {
fmt.Fprintf(w, "#%d\t%s\t%.2f mWh\t%.2f mWh\t%.2f mWh\t%.2f mWh\t%.2f V\t\n", index, batt.State, batt.Current, batt.Full, batt.Design, batt.ChargeRate, batt.Voltage)
}
w.Flush()
fmt.Fprintln(stdout, "")
ctx.terminal.Println()
return nil
}
Loading
Loading