Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor: rename cmd struct fields #13

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions cmd/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

func NewAttachCmd() *AttachCmd {
c := &AttachCmd{Cmd: Cmd{
fs: flag.NewFlagSet("attach", flag.ExitOnError),
alias: []string{"a"},
shortDesc: "Attach to Kakoune session with a new client.",
usageLine: "[options] [file] [+<line>[:<col]]",
sessionReq: true,
fs: flag.NewFlagSet("attach", flag.ExitOnError),
aliases: []string{"a"},
description: "Attach to Kakoune session with a new client.",
usageLine: "[options] [file] [+<line>[:<col]]",
sessionRequired: true,
}}
c.fs.StringVar(&c.session, "s", "", "session")
return c
Expand Down
12 changes: 6 additions & 6 deletions cmd/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (

func NewCatCmd() *CatCmd {
c := &CatCmd{Cmd: Cmd{
fs: flag.NewFlagSet("cat", flag.ExitOnError),
alias: []string{""},
shortDesc: "Print contents of a buffer to stdout.",
usageLine: "[options]",
sessionReq: true,
clientReq: true,
fs: flag.NewFlagSet("cat", flag.ExitOnError),
aliases: []string{""},
description: "Print contents of a buffer to stdout.",
usageLine: "[options]",
sessionRequired: true,
clientRequired: true,
}}
c.fs.StringVar(&c.session, "s", "", "session")
c.fs.StringVar(&c.client, "c", "", "client")
Expand Down
24 changes: 12 additions & 12 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ type Runner interface {
}

type Cmd struct {
fs *flag.FlagSet
alias []string
shortDesc string
usageLine string
fs *flag.FlagSet
aliases []string
description string
usageLine string

session string
client string
buffer string

sessionReq bool
clientReq bool
bufferReq bool
sessionRequired bool
clientRequired bool
bufferRequired bool

kctx *kak.Context

Expand All @@ -39,7 +39,7 @@ type Cmd struct {

func (c *Cmd) Run() error { return nil }
func (c *Cmd) Name() string { return c.fs.Name() }
func (c *Cmd) Alias() []string { return c.alias }
func (c *Cmd) Alias() []string { return c.aliases }

var (
errNoSession = errors.New("no session in context")
Expand Down Expand Up @@ -77,21 +77,21 @@ func (c *Cmd) Init(args []string) error {
Buffer: kak.Buffer{Name: c.buffer},
}

if c.sessionReq && c.kctx.Session.Name == "" {
if c.sessionRequired && c.kctx.Session.Name == "" {
return errNoSession
}
if c.clientReq && c.kctx.Client.Name == "" {
if c.clientRequired && c.kctx.Client.Name == "" {
return errNoClient
}
if c.bufferReq && c.kctx.Buffer.Name == "" {
if c.bufferRequired && c.kctx.Buffer.Name == "" {
return errNoBuffer
}

return nil
}

func (c *Cmd) usage() {
fmt.Println(c.shortDesc)
fmt.Println(c.description)
fmt.Println()

fmt.Println("USAGE")
Expand Down
9 changes: 4 additions & 5 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (

func NewEditCmd() *EditCmd {
c := &EditCmd{Cmd: Cmd{
fs: flag.NewFlagSet("edit", flag.ExitOnError),
alias: []string{"e"},
shortDesc: "Edit file. In session and client, if set.",
usageLine: "[options] [file] [+<line>[:<col>]]",
fs: flag.NewFlagSet("edit", flag.ExitOnError),
aliases: []string{"e"},
description: "Edit file. In session and client, if set.",
usageLine: "[options] [file] [+<line>[:<col>]]",
}}
// TODO add flag that allows creating new files (removes -existing)
c.fs.StringVar(&c.session, "s", "", "session")
c.fs.StringVar(&c.client, "c", "", "client")
return c
Expand Down
10 changes: 5 additions & 5 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

func NewEnvCmd() *EnvCmd {
c := &EnvCmd{Cmd: Cmd{
fs: flag.NewFlagSet("env", flag.ExitOnError),
alias: []string{""},
shortDesc: "Print current Kakoune context set by environment to stdout.",
usageLine: "[options]",
sessionReq: true,
fs: flag.NewFlagSet("env", flag.ExitOnError),
aliases: []string{""},
description: "Print current Kakoune context set by environment to stdout.",
usageLine: "[options]",
sessionRequired: true,
}}
c.fs.BoolVar(&c.json, "json", false, "json output")
return c
Expand Down
10 changes: 5 additions & 5 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

func NewGetCmd() *GetCmd {
c := &GetCmd{Cmd: Cmd{
fs: flag.NewFlagSet("get", flag.ExitOnError),
alias: []string{""},
shortDesc: "Get states from Kakoune context.",
usageLine: "[options] (<%val{..}> | <%opt{..}> | <%reg{..}> | <%sh{..}>)",
sessionReq: true,
fs: flag.NewFlagSet("get", flag.ExitOnError),
aliases: []string{""},
description: "Get states from Kakoune context.",
usageLine: "[options] (<%val{..}> | <%opt{..}> | <%reg{..}> | <%sh{..}>)",
sessionRequired: true,
}}
c.fs.StringVar(&c.session, "s", "", "session")
c.fs.StringVar(&c.client, "c", "", "client")
Expand Down
8 changes: 4 additions & 4 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ var initKak string

func NewInitCmd() *InitCmd {
c := &InitCmd{Cmd: Cmd{
fs: flag.NewFlagSet("init", flag.ExitOnError),
alias: []string{""},
shortDesc: "Print Kakoune command definitions to stdout.",
usageLine: "",
fs: flag.NewFlagSet("init", flag.ExitOnError),
aliases: []string{""},
description: "Print Kakoune command definitions to stdout.",
usageLine: "",
}}
return c
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

func NewKillCmd() *KillCmd {
c := &KillCmd{Cmd: Cmd{
fs: flag.NewFlagSet("kill", flag.ExitOnError),
alias: []string{""},
shortDesc: "Terminate Kakoune session.",
usageLine: "[options]",
fs: flag.NewFlagSet("kill", flag.ExitOnError),
aliases: []string{""},
description: "Terminate Kakoune session.",
usageLine: "[options]",
}}
c.fs.BoolVar(&c.all, "a", false, "all sessions")
c.fs.StringVar(&c.session, "s", "", "session")
Expand Down
8 changes: 4 additions & 4 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

func NewListCmd() *ListCmd {
c := &ListCmd{Cmd: Cmd{
fs: flag.NewFlagSet("list", flag.ExitOnError),
alias: []string{"ls", "l"},
shortDesc: "List Kakoune sessions and clients.",
usageLine: "[options]",
fs: flag.NewFlagSet("list", flag.ExitOnError),
aliases: []string{"ls", "l"},
description: "List Kakoune sessions and clients.",
usageLine: "[options]",
}}
c.fs.BoolVar(&c.json, "json", false, "json output")
return c
Expand Down
8 changes: 4 additions & 4 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

func NewNewCmd() *NewCmd {
c := &NewCmd{Cmd: Cmd{
fs: flag.NewFlagSet("new", flag.ExitOnError),
alias: []string{"n"},
shortDesc: "Start new headless Kakoune session.",
usageLine: "[<name>]",
fs: flag.NewFlagSet("new", flag.ExitOnError),
aliases: []string{"n"},
description: "Start new headless Kakoune session.",
usageLine: "[<name>]",
}}
return c
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
//go:embed embed/help
var helpTxt string

var UnknownSubcommand = errors.New("unknown subcommand")
var ErrUnknownSubcommand = errors.New("unknown subcommand")

func Root(args []string) error {
if len(args) < 1 || args[0] == "-h" || args[0] == "--help" {
Expand Down Expand Up @@ -42,7 +42,7 @@ func Root(args []string) error {
}
}

return fmt.Errorf("can't run %s: %w", subcommand, UnknownSubcommand)
return fmt.Errorf("can't run %s: %w", subcommand, ErrUnknownSubcommand)
}

func containsString(s []string, e string) bool {
Expand Down
8 changes: 4 additions & 4 deletions cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

func NewSendCmd() *SendCmd {
c := &SendCmd{Cmd: Cmd{
fs: flag.NewFlagSet("send", flag.ExitOnError),
alias: []string{"s"},
shortDesc: "Send commands to Kakoune context.",
usageLine: "[options] <command>",
fs: flag.NewFlagSet("send", flag.ExitOnError),
aliases: []string{"s"},
description: "Send commands to Kakoune context.",
usageLine: "[options] <command>",
}}
c.fs.BoolVar(&c.all, "a", false, "all sessions and clients")
c.fs.StringVar(&c.session, "s", "", "session")
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {

err := cmd.Root(os.Args[1:])

if err != nil && errors.Is(err, cmd.UnknownSubcommand) {
if err != nil && errors.Is(err, cmd.ErrUnknownSubcommand) {
err = cmd.External(os.Args[1:], err)
}
if err != nil {
Expand Down