Skip to content

Commit

Permalink
Merge pull request #50 from foomo/add-check
Browse files Browse the repository at this point in the history
feat: add check command
  • Loading branch information
franklinkim committed Dec 13, 2023
2 parents f19376c + 7f2785c commit 910ed86
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
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

0 comments on commit 910ed86

Please sign in to comment.