Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 17, 2021
1 parent 6434ee3 commit 7bacbe9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
5 changes: 2 additions & 3 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ func findOrRunSession(c *EditCmd, fp *kak.Filepath) error {
}

func connectOrEditInClient(c *EditCmd, fp *kak.Filepath) error {
switch c.kctx.Client.Name {
case "":
if c.kctx.Client.Name == "" {
// if no client, attach to session with new client
if err := kak.Connect(c.kctx, fp); err != nil {
return err
}
default:
} else {
// if client set, send 'edit [file]' to client
sb := strings.Builder{}
sb.WriteString(fmt.Sprintf("edit -existing %s", fp.Name))
Expand Down
5 changes: 2 additions & 3 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ type EnvCmd struct {
}

func (c *EnvCmd) Run() error {
switch c.json {
case true:
if c.json {
j, err := json.MarshalIndent(
map[string]string{
"session": c.session,
Expand All @@ -35,7 +34,7 @@ func (c *EnvCmd) Run() error {
return err
}
fmt.Println(string(j))
case false:
} else {
fmt.Printf("session: %s\n", c.session)
fmt.Printf("client: %s\n", c.client)
}
Expand Down
13 changes: 6 additions & 7 deletions cmd/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ type KillCmd struct {
func (c *KillCmd) Run() error {
sendCmd := "kill"

switch c.allSessions {
case false:
// TODO need to somehow trigger "no session" err
if err := kak.Send(c.kctx, sendCmd); err != nil {
return err
}
case true:
if c.allSessions {
sessions, err := kak.Sessions()
if err != nil {
return err
Expand All @@ -47,6 +41,11 @@ func (c *KillCmd) Run() error {
return err
}
}
} else {
// TODO need to somehow trigger "no session" err
if err := kak.Send(c.kctx, sendCmd); err != nil {
return err
}
}

return nil
Expand Down
7 changes: 2 additions & 5 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func (c *ListCmd) Run() error {
return err
}

switch c.json {

case true:
if c.json {
type session struct {
Name string `json:"name"`
Clients []string `json:"clients"`
Expand Down Expand Up @@ -65,8 +63,7 @@ func (c *ListCmd) Run() error {
}

fmt.Println(string(j))

case false:
} else {
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 1, '\t', 0)

Expand Down
13 changes: 6 additions & 7 deletions cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ func (c *SendCmd) Run() error {
// TODO probably need to do some shell escaping here
sendCmd := strings.Join(c.fs.Args(), " ")

switch c.allClients {
case false:
// TODO: need to trigger "session not set" error
if err := kak.Send(c.kctx, sendCmd); err != nil {
return err
}
case true:
if c.allClients {
sessions, err := kak.Sessions()
if err != nil {
return err
Expand All @@ -53,6 +47,11 @@ func (c *SendCmd) Run() error {
return err
}
}
} else {
// TODO: need to trigger "session not set" error
if err := kak.Send(c.kctx, sendCmd); err != nil {
return err
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion kak/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Run(kctx *Context, kakArgs []string, fp *Filepath) error {
case "-c":
kakExecArgs = append(kakExecArgs, "-c", kctx.Session.Name)
default:
return errors.New(fmt.Sprintf("unknown argument to Run: %s", a))
return errors.New(fmt.Sprintf("Unknown argument to Run: %s", a))
}
}

Expand Down

0 comments on commit 7bacbe9

Please sign in to comment.