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

feat: add check command #50

Merged
merged 1 commit into from
Dec 13, 2023
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
71 changes: 71 additions & 0 deletions pkg/command/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package command

import (
"context"

"github.com/foomo/posh/pkg/command/tree"
"github.com/foomo/posh/pkg/log"
"github.com/foomo/posh/pkg/prompt/check"
"github.com/foomo/posh/pkg/prompt/goprompt"
"github.com/foomo/posh/pkg/readline"
)

type (
Check struct {
l log.Logger
tree tree.Root
check check.Check
checkers check.Checkers
}
Option func(*Check)
)

// ------------------------------------------------------------------------------------------------
// ~ Constructor
// ------------------------------------------------------------------------------------------------

func NewCheck(l log.Logger, checkers ...check.Checker) *Check {
inst := &Check{
l: l,
check: check.DefaultCheck,
checkers: checkers,
}
inst.tree = tree.New(&tree.Node{
Name: "check",
Description: "Print all system checks",
Execute: inst.run,
})
return inst
}

// ------------------------------------------------------------------------------------------------
// ~ Public methods
// ------------------------------------------------------------------------------------------------

func (c *Check) Name() string {
return c.tree.Node().Name
}

func (c *Check) Description() string {
return c.tree.Node().Description
}

func (c *Check) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
return c.tree.Complete(ctx, r)
}

func (c *Check) Execute(ctx context.Context, r *readline.Readline) error {
return c.tree.Execute(ctx, r)
}

func (c *Check) Help(ctx context.Context, r *readline.Readline) string {
return c.tree.Help(ctx, r)
}

// ------------------------------------------------------------------------------------------------
// ~ Private methods
// ------------------------------------------------------------------------------------------------

func (c *Check) run(ctx context.Context, r *readline.Readline) error {
return c.check(ctx, c.l, c.checkers)
}
3 changes: 3 additions & 0 deletions pkg/prompt/check/checkers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package check

type Checkers []Checker