Skip to content

Commit

Permalink
redirect terminal when elevated mode
Browse files Browse the repository at this point in the history
  • Loading branch information
creativeprojects committed Jul 18, 2020
1 parent 294a499 commit af04717
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion commands.go
Expand Up @@ -324,7 +324,6 @@ func statusSchedule(c *config.Config, flags commandLineFlags, args []string) err
func testElevationCommand(c *config.Config, flags commandLineFlags, args []string) error {
if flags.isChild {
client := remote.NewClient(flags.parentPort)
term.SetOutput(term.NewRemoteTerm(client))
term.Print("first line", "\n")
term.Println("second", "one")
term.Printf("value = %d", 11)
Expand Down
3 changes: 1 addition & 2 deletions logger.go
Expand Up @@ -7,8 +7,7 @@ import (
"github.com/creativeprojects/resticprofile/remote"
)

func setupRemoteLogger(flags commandLineFlags) {
client := remote.NewClient(flags.parentPort)
func setupRemoteLogger(client *remote.Client) {
logger := clog.NewLogger(client)
client.SetLogPrefix("elevated user: ")
clog.SetDefaultLogger(logger)
Expand Down
8 changes: 7 additions & 1 deletion main.go
Expand Up @@ -11,11 +11,14 @@ import (
"text/tabwriter"
"time"

"github.com/creativeprojects/resticprofile/term"

"github.com/creativeprojects/clog"
"github.com/creativeprojects/resticprofile/config"
"github.com/creativeprojects/resticprofile/constants"
"github.com/creativeprojects/resticprofile/filesearch"
"github.com/creativeprojects/resticprofile/priority"
"github.com/creativeprojects/resticprofile/remote"
"github.com/mackerelio/go-osstat/memory"
)

Expand Down Expand Up @@ -82,7 +85,10 @@ func main() {
}
} else if flags.isChild {
// use a remote logger
setupRemoteLogger(flags)
client := remote.NewClient(flags.parentPort)
setupRemoteLogger(client)
// also redirect the terminal through the client
term.SetOutput(term.NewRemoteTerm(client))
} else {
// Use the console logger
setupConsoleLogger(flags)
Expand Down
3 changes: 1 addition & 2 deletions win/taskscheduler.go
Expand Up @@ -4,7 +4,6 @@ package win

import (
"fmt"
"os"
"os/user"
"strings"
"text/tabwriter"
Expand Down Expand Up @@ -251,7 +250,7 @@ func (s *TaskScheduler) Status() error {
if registeredTask == nil {
return fmt.Errorf("%w: %s", ErrorNotRegistered, taskName)
}
writer := tabwriter.NewWriter(os.Stdout, 2, 2, 2, ' ', 0)
writer := tabwriter.NewWriter(term.GetOutput(), 2, 2, 2, ' ', 0)
fmt.Fprintf(writer, "Task\t%s\n", registeredTask.Path)
fmt.Fprintf(writer, "User\t%s\n", registeredTask.Definition.Principal.UserID)
if registeredTask.Definition.Actions != nil && len(registeredTask.Definition.Actions) > 0 {
Expand Down

0 comments on commit af04717

Please sign in to comment.