Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
bare bones documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
perigrin committed Oct 29, 2020
1 parent 449ca62 commit 425b80a
Show file tree
Hide file tree
Showing 25 changed files with 529 additions and 206 deletions.
37 changes: 29 additions & 8 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/joyent/kosh/template"
)

// Config is the interface for the configuration object for the full app
type Config interface {
GetVersion() string

Expand All @@ -32,7 +33,7 @@ type Config interface {
conch.Config
}

// Config struct
// DefaultConfig is the default configuration struct
type DefaultConfig struct {
Version string
GitRev string
Expand All @@ -46,15 +47,31 @@ type DefaultConfig struct {
logger.Logger
}

func (c *DefaultConfig) GetVersion() string { return c.Version }
func (c *DefaultConfig) GetURL() string { return c.ConchURL }
func (c *DefaultConfig) GetToken() string { return c.ConchToken }
// GetVersion returns the current app version
func (c *DefaultConfig) GetVersion() string { return c.Version }

// GetURL returns the current conch API url
func (c *DefaultConfig) GetURL() string { return c.ConchURL }

// GetToken returns the current conch API token
func (c *DefaultConfig) GetToken() string { return c.ConchToken }

// GetLogger returns the current logger instance
func (c *DefaultConfig) GetLogger() logger.Logger { return c.Logger }

func (c *DefaultConfig) SetURL(URL string) { c.ConchURL = URL }
func (c *DefaultConfig) SetToken(token string) { c.ConchToken = token }
func (c *DefaultConfig) GetOutputJSON() bool { return c.OutputJSON }
func (c *DefaultConfig) SetOutputJSON(p bool) { c.OutputJSON = p }
// SetURL updates the current conch API url
func (c *DefaultConfig) SetURL(URL string) { c.ConchURL = URL }

// SetToken updates the current conch API token being used
func (c *DefaultConfig) SetToken(token string) { c.ConchToken = token }

// GetOutputJSON returns whether JSON is used for output or not
func (c *DefaultConfig) GetOutputJSON() bool { return c.OutputJSON }

// SetOutputJSON sets whether to use JSOn for output or not
func (c *DefaultConfig) SetOutputJSON(p bool) { c.OutputJSON = p }

// SetLogger sets the configured logger instance
func (c *DefaultConfig) SetLogger(l logger.Logger) { c.Logger = l }

// NewConfig takes a Version and a GitRev and returns a Config object
Expand All @@ -81,6 +98,7 @@ const configTemplate = `
---
`

// String returns a string implementation of the config object
func (c *DefaultConfig) String() string {
t, err := template.NewTemplate().Parse(configTemplate)
if err != nil {
Expand All @@ -100,6 +118,7 @@ func (c *DefaultConfig) ConchClient() *conch.Client {
return conch.New(c).UserAgent(userAgent)
}

// Renderer returns a function that will render to STDOUT
func (c *DefaultConfig) Renderer() func(interface{}) {
return c.RenderTo(os.Stdout)
}
Expand All @@ -112,6 +131,8 @@ func renderJSON(i interface{}) string {
return string(b)
}

// RenderTo returns a function tha renders to a given io.Writer based on the
// configuraton and datatype
func (c *DefaultConfig) RenderTo(w io.Writer) func(interface{}) {
return func(i interface{}) {
if c.OutputJSON {
Expand Down
4 changes: 2 additions & 2 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestRender(t *testing.T) {

{
Name: " display(conch.GetHardwareVendors())",
Do: func() { display(conch.GetHardwareVendors()) },
Do: func() { display(conch.GetAllHardwareVendors()) },
},

{
Expand All @@ -208,7 +208,7 @@ func TestRender(t *testing.T) {

{
Name: " display(conch.GetOrganizations())",
Do: func() { display(conch.GetOrganizations()) },
Do: func() { display(conch.GetAllOrganizations()) },
},

{
Expand Down
6 changes: 3 additions & 3 deletions cli/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func cmdCreateProduct(cfg Config) func(*cli.Cmd) {
cmd.Action = func() {
conch := cfg.ConchClient()
validationPlan := conch.GetValidationPlanByName(*validationPlanOpt)
vendor := conch.GetHardwareVendorByID(*vendor)
vendor := conch.GetHardwareVendorByName(*vendor)
create := types.HardwareProductCreate{
Name: types.MojoStandardPlaceholder(*name),
Alias: types.MojoStandardPlaceholder(*alias),
Expand Down Expand Up @@ -91,7 +91,7 @@ func hardwareCmd(cfg Config) func(*cli.Cmd) {

cmd.Command("vendors", "Work with hardware vendors", func(cmd *cli.Cmd) {
cmd.Command("get ls", "Get a list of all hardware vendors", func(cmd *cli.Cmd) {
display(conch.GetHardwareVendors())
display(conch.GetAllHardwareVendors())
})
cmd.Command("create", "Create a hardware vendor", func(cmd *cli.Cmd) {
name := cmd.StringArg("NAME", "", "The name of the hardware vendor.")
Expand All @@ -107,7 +107,7 @@ func hardwareCmd(cfg Config) func(*cli.Cmd) {

// grab the Vendor for the given ID
cmd.Before = func() {
hv = conch.GetHardwareVendorByID(*idArg)
hv = conch.GetHardwareVendorByName(*idArg)
if (hv == types.HardwareVendor{}) {
fmt.Println("Hardware Vendor not found for " + *idArg)
cli.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cli/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func organizationsCmd(cfg Config) func(cmd *cli.Cmd) {
}
cmd.Command("get ls", "Get a list of all organizations", func(cmd *cli.Cmd) {
cmd.Action = func() {
display(conch.GetOrganizations())
display(conch.GetAllOrganizations())
}
})

Expand Down
Loading

0 comments on commit 425b80a

Please sign in to comment.