Skip to content

Commit

Permalink
Firx one-line-command broken after AppplicationState refactoring (#179)
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Aug 9, 2023
1 parent af92984 commit 255b52b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bapps/go_prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewPromptApp(config *configs.Config, opts ...AppOption) BApp {
o(opt)
}

config.Logger = opt.logger
config.SetLogger(opt.logger)

// use workspace path to open&store history log
hh := history.NewHistoryHelper(config.WorkspacePath)
Expand Down
1 change: 1 addition & 0 deletions bapps/olc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (a *olcApp) Run(start framework.State) {
if cmd.muted {
os.Stdout = stdout
}
app.SetupCommands()
}
}

Expand Down
16 changes: 13 additions & 3 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package configs
import (
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path"
Expand All @@ -29,7 +29,17 @@ type Config struct {
// backup workspace path, default $PWD/bw_workspace
WorkspacePath string `yaml:"WorkspacePath"`

Logger *log.Logger
logger *log.Logger
}

func (c *Config) SetLogger(logger *log.Logger) {
c.logger = logger
}

func (c *Config) Log(v ...any) {
if c.logger != nil {
c.logger.Println(v...)
}
}

func (c *Config) load() error {
Expand All @@ -43,7 +53,7 @@ func (c *Config) load() error {
return err
}
defer f.Close()
bs, err := ioutil.ReadAll(f)
bs, err := io.ReadAll(f)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions states/app_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (app *ApplicationState) Label() string {
}

func (app *ApplicationState) Process(cmd string) (framework.State, error) {
app.config.Logger.Println("[INFO] begin to process command", cmd)
app.config.Log("[INFO] begin to process command", cmd)
app.core.Process(cmd)
// perform sub state transfer
for key, state := range app.states {
Expand All @@ -63,7 +63,7 @@ func (app *ApplicationState) Close() {
}

func (app *ApplicationState) SetNext(state framework.State) {
app.config.Logger.Println("[WARNING] SetNext called for ApplicationState, which is not expected.")
app.config.Log("[WARNING] SetNext called for ApplicationState, which is not expected.")
}

func (app *ApplicationState) NextState() framework.State {
Expand Down

0 comments on commit 255b52b

Please sign in to comment.