Skip to content
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
16 changes: 10 additions & 6 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type GroupCommand struct {
Descriptor string
}

func addCommandGroup(cmd *cobra.Command, h handlers.Handler, title string, f func(handlers.Handler, string) []*cobra.Command) {
func addCommandGroup(cmd *cobra.Command, r handlers.Runtime, title string, f func(handlers.Runtime, string) []*cobra.Command) {
id := uuid.New().String()
children := f(h, id)
children := f(r, id)
if len(children) > 0 {
cmd.AddGroup(&cobra.Group{ID: id, Title: title})
for _, ele := range children {
Expand Down Expand Up @@ -85,7 +85,8 @@ func makeCommand(name, group string, f func() []*cobra.Command, desc string) *co
return cmd
}

func assetCommands(h handlers.Handler, id string) []*cobra.Command {
func assetCommands(r handlers.Runtime, id string) []*cobra.Command {
h := handlers.NewHandler(r)
return makeGroupCommand([]GroupCommand{
GroupCommand{"get", id, h.GetCommands, "asset"},
GroupCommand{"describe", id, h.DescribeCommands, "asset"},
Expand All @@ -104,7 +105,8 @@ func assetCommands(h handlers.Handler, id string) []*cobra.Command {
})
}

func platformCommands(h handlers.Handler, id string) []*cobra.Command {
func platformCommands(r handlers.Runtime, id string) []*cobra.Command {
h := handlers.NewHandler(r)
return makeGroupCommand([]GroupCommand{
GroupCommand{"api", id, h.ApiCommands, "platform"},
GroupCommand{"inspect", id, h.InspectCommands, "platform"},
Expand All @@ -114,14 +116,16 @@ func platformCommands(h handlers.Handler, id string) []*cobra.Command {
})
}

func datasetCommands(h handlers.Handler, id string) []*cobra.Command {
func datasetCommands(r handlers.Runtime, id string) []*cobra.Command {
h := handlers.NewHandler(r)
return makeGroupCommand([]GroupCommand{
GroupCommand{"load", id, h.LoadCommands, "dataset"},
GroupCommand{"dump", id, h.DumpCommands, "dataset"},
})
}

func pluginCommands(h handlers.Handler, id string) []*cobra.Command {
func pluginCommands(r handlers.Runtime, id string) []*cobra.Command {
h := handlers.NewHandler(r)
return makeGroupCommand([]GroupCommand{
GroupCommand{"local-aaa", id, h.LocalAAACommands, "localaaa"},
GroupCommand{"client", id, h.LocalClientCommands, "localclient"},
Expand Down
22 changes: 11 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const description = `Manage Itential Platform
Find more information at: https://docs.itential.com
`

func loadCommands(cmd *cobra.Command, h handlers.Handler, cfg *config.Config) {
addCommandGroup(cmd, h, "Asset Commands:", assetCommands)
if cfg.FeaturesDatasetsEnabled {
addCommandGroup(cmd, h, "Dataset Commands:", datasetCommands)
func loadCommands(cmd *cobra.Command, runtime handlers.Runtime) {
addCommandGroup(cmd, runtime, "Asset Commands:", assetCommands)
if runtime.Config.FeaturesDatasetsEnabled {
addCommandGroup(cmd, runtime, "Dataset Commands:", datasetCommands)
}
addCommandGroup(cmd, h, "Platform Commands:", platformCommands)
addCommandGroup(cmd, h, "Plugin Commands:", pluginCommands)
addCommandGroup(cmd, runtime, "Platform Commands:", platformCommands)
addCommandGroup(cmd, runtime, "Plugin Commands:", pluginCommands)
}

func versionCommand() *cobra.Command {
Expand All @@ -50,7 +50,7 @@ func versionCommand() *cobra.Command {
return cmd
}

func Do(iapClient *client.IapClient, cfg *config.Config) *cobra.Command {
func Do(c client.Client, cfg *config.Config) *cobra.Command {
var cmd = &cobra.Command{
Use: "ipctl",
Short: strings.Split(description, "\n")[0],
Expand All @@ -60,16 +60,16 @@ func Do(iapClient *client.IapClient, cfg *config.Config) *cobra.Command {
cmd.CompletionOptions.HiddenDefaultCmd = true
cmd.SetHelpCommand(&cobra.Command{Hidden: true})

h := handlers.NewHandler(iapClient, cfg)
runtime := handlers.NewRuntime(c, cfg)

cmd.PersistentFlags().BoolVar(&h.Runtime.Verbose, "verbose", h.Runtime.Verbose, "Enable verbose output")
cmd.PersistentFlags().StringVar(&h.Runtime.Config.TerminalDefaultOutput, "output", h.Runtime.Config.TerminalDefaultOutput, "Output format")
cmd.PersistentFlags().BoolVar(&runtime.Verbose, "verbose", runtime.Verbose, "Enable verbose output")
cmd.PersistentFlags().StringVar(&runtime.Config.TerminalDefaultOutput, "output", runtime.Config.TerminalDefaultOutput, "Output format")

// Note: Values are read during /pkg/config's initialization
cmd.PersistentFlags().String("config", "", "Path to the configuration file")
cmd.PersistentFlags().String("profile", "", "Connection profile to use")

loadCommands(cmd, h, cfg)
loadCommands(cmd, runtime)

cmd.AddCommand(versionCommand())

Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package handlers

import (
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewAccountHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewAccountHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewAccountRunner(c, cfg),
runners.NewAccountRunner(r.Client, r.Config),
desc[accountsDescriptor],
nil,
)
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/adapter_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package handlers

import (
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewAdapterModelHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewAdapterModelHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewAdapterModelRunner(c, cfg),
runners.NewAdapterModelRunner(r.Client, r.Config),
desc[adapterModels],
nil,
)
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ package handlers
import (
"github.com/itential/ipctl/internal/flags"
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewAdapterHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewAdapterHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewAdapterRunner(c, cfg),
runners.NewAdapterRunner(r.Client, r.Config),
desc[adaptersDescriptor],
&AssetHandlerFlags{
Create: &flags.AdapterCreateOptions{},
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/analytic_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ package handlers
import (
"github.com/itential/ipctl/internal/flags"
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewAnalyticTemplateHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewAnalyticTemplateHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewAnalyticTemplateRunner(c, cfg),
runners.NewAnalyticTemplateRunner(r.Client, r.Config),
desc[analyticTemplatesDescriptor],
&AssetHandlerFlags{
Get: &flags.AnalyticTemplateGetOptions{},
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ package handlers
import (
"github.com/itential/ipctl/internal/flags"
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
"github.com/spf13/cobra"
)

Expand All @@ -17,9 +15,9 @@ type ApiHandler struct {
Descriptor DescriptorMap
}

func NewApiHandler(c client.Client, cfg *config.Config, desc Descriptors) ApiHandler {
func NewApiHandler(r Runtime, desc Descriptors) ApiHandler {
return ApiHandler{
Runner: runners.NewApiRunner(c),
Runner: runners.NewApiRunner(r.Client),
Descriptor: desc[apiDescriptor],
}

Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package handlers

import (
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewApplicationHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewApplicationHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewApplicationRunner(c, cfg),
runners.NewApplicationRunner(r.Client, r.Config),
desc[applicationsDescriptor],
nil,
)
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/automations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ package handlers
import (
"github.com/itential/ipctl/internal/flags"
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewAutomationHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewAutomationHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewAutomationRunner(c, cfg),
runners.NewAutomationRunner(r.Client, r.Config),
desc[automationsDescriptor],
&AssetHandlerFlags{
Create: &flags.AutomationCreateOptions{},
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/command_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ package handlers
import (
"github.com/itential/ipctl/internal/flags"
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewCommandTemplateHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewCommandTemplateHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewCommandTemplateRunner(c, cfg),
runners.NewCommandTemplateRunner(r.Client, r.Config),
desc[commandTemplatesDescriptor],
&AssetHandlerFlags{
Get: &flags.CommandTemplateGetOptions{},
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/configuration_parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package handlers

import (
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewConfigurationParserHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewConfigurationParserHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewConfigurationParserRunner(c, cfg),
runners.NewConfigurationParserRunner(r.Client, r.Config),
desc[configurationParsersDescriptor],
nil,
)
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/devicegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ package handlers
import (
"github.com/itential/ipctl/internal/flags"
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewDeviceGroupHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewDeviceGroupHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewDeviceGroupRunner(c, cfg),
runners.NewDeviceGroupRunner(r.Client, r.Config),
desc[deviceGroupsDescriptor],
&AssetHandlerFlags{
Create: &flags.DeviceGroupCreateOptions{},
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package handlers

import (
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewDeviceHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewDeviceHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewDeviceRunner(c, cfg),
runners.NewDeviceRunner(r.Client, r.Config),
desc[devicesDescriptor],
nil,
)
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/gctrees.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package handlers

import (
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewGoldenConfigHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewGoldenConfigHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewGoldenConfigRunner(c, cfg),
runners.NewGoldenConfigRunner(r.Client, r.Config),
desc[gctreesDescriptor],
nil,
)
Expand Down
6 changes: 2 additions & 4 deletions internal/handlers/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ package handlers
import (
"github.com/itential/ipctl/internal/flags"
"github.com/itential/ipctl/internal/runners"
"github.com/itential/ipctl/pkg/client"
"github.com/itential/ipctl/pkg/config"
)

func NewGroupHandler(c client.Client, cfg *config.Config, desc Descriptors) AssetHandler {
func NewGroupHandler(r Runtime, desc Descriptors) AssetHandler {
return NewAssetHandler(
runners.NewGroupRunner(c, cfg),
runners.NewGroupRunner(r.Client, r.Config),
desc[groupsDescriptor],
&AssetHandlerFlags{
Create: &flags.GroupCreateOptions{},
Expand Down
Loading