Skip to content

Commit

Permalink
add KakContext struct
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 14, 2021
1 parent da4f0c3 commit 41ed47c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 15 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"os"
"strings"

"github.com/kkga/kks/kak"
)

type Runner interface {
Expand All @@ -27,6 +29,8 @@ type Cmd struct {
sessionReq bool
clientReq bool
bufferReq bool

kakContext kak.Context
}

type EnvContext struct {
Expand All @@ -52,10 +56,19 @@ func (c *Cmd) Init(args []string) error {
return err
}

if c.sessionReq && c.session == "" {
c.kakContext = kak.Context{
Session: kak.Session{Name: c.session},
Client: kak.Client{Name: c.client},
Buffer: kak.Buffer{Name: c.buffer},
}

if c.sessionReq && c.kakContext.Session.Name == "" {
return errors.New("no session in context")
}
if c.clientReq && c.client == "" {
if c.clientReq && c.kakContext.Client.Name == "" {
return errors.New("no client in context")
}
if c.bufferReq && c.kakContext.Buffer.Name == "" {
return errors.New("no client in context")
}

Expand Down
9 changes: 5 additions & 4 deletions kak/kak.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"strings"
)

type Session struct {
Name string
// clients []string
// dir string
type Context struct {
Session Session
Client Client
Buffer Buffer
}

type Session struct{ Name string }
type Client struct{ Name string }
type Buffer struct{ Name string }

Expand Down

0 comments on commit 41ed47c

Please sign in to comment.