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
7 changes: 1 addition & 6 deletions internal/runners/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package runners

import (
"embed"
"fmt"

"github.com/itential/ipctl/pkg/client"
Expand All @@ -14,9 +13,6 @@ import (
"github.com/itential/ipctl/pkg/services"
)

//go:embed templates/accounts/*.tmpl
var content embed.FS

type AccountRunner struct {
config *config.Config
service *services.AccountService
Expand Down Expand Up @@ -65,15 +61,14 @@ func (r *AccountRunner) Describe(in Request) (*Response, error) {
return nil, fmt.Errorf("account `%s` does not exist", in.Args[0])
}

tmpl, err := content.ReadFile("describe.tmpl")
tmpl, err := templates.ReadFile("templates/accounts/describe.tmpl")
if err != nil {
logger.Fatal(err, "failed to load template")
}

return &Response{
Object: account,
Template: string(tmpl),
//Template: "Username: {{.Username}}",
}, nil
}

Expand Down
74 changes: 48 additions & 26 deletions internal/runners/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ func NewProfileRunner(client client.Client, cfg *config.Config) *ProfileRunner {
}
}

//////////////////////////////////////////////////////////////////////////////
// Reader Interface
//
/*
******************************************************************************
Reader interface
******************************************************************************
*/

// Get implements the `get profiles` command
func (r *ProfileRunner) Get(in Request) (*Response, error) {
Expand All @@ -46,7 +48,7 @@ func (r *ProfileRunner) Get(in Request) (*Response, error) {
}

return &Response{
Keys: []string{"name", "description"},
Keys: []string{"id", "description"},
Object: profiles,
}, nil
}
Expand All @@ -62,14 +64,22 @@ func (r *ProfileRunner) Describe(in Request) (*Response, error) {
return nil, err
}

tmpl, err := templates.ReadFile("templates/profiles/describe.tmpl")
if err != nil {
logger.Fatal(err, "failed to load template")
}

return &Response{
Object: profile,
Object: profile,
Template: string(tmpl),
}, nil
}

//////////////////////////////////////////////////////////////////////////////
// Writer Interface
//
/*
******************************************************************************
Writer interface
******************************************************************************
*/

// Create is the implementation of the command `ccreate profile <name>`
func (r *ProfileRunner) Create(in Request) (*Response, error) {
Expand Down Expand Up @@ -128,9 +138,11 @@ func (r *ProfileRunner) Clear(in Request) (*Response, error) {
}, nil
}

//////////////////////////////////////////////////////////////////////////////
// Copier Interface
//
/*
******************************************************************************
Copier interface
******************************************************************************
*/

// Copy implements the `copy profile <name> <dst>` command
func (r *ProfileRunner) Copy(in Request) (*Response, error) {
Expand Down Expand Up @@ -191,9 +203,11 @@ func (r *ProfileRunner) CopyTo(profile string, in any, replace bool) (any, error
return svc.Import(in.(services.Profile))
}

//////////////////////////////////////////////////////////////////////////////
// Importer Interface
//
/*
******************************************************************************
Importer interface
******************************************************************************
*/

// Import implements the command `import profile <path>`
func (r *ProfileRunner) Import(in Request) (*Response, error) {
Expand All @@ -216,9 +230,11 @@ func (r *ProfileRunner) Import(in Request) (*Response, error) {
}, nil
}

//////////////////////////////////////////////////////////////////////////////
// Exporter Interface
//
/*
******************************************************************************
Exporter interface
******************************************************************************
*/

// Export is the implementation of the command `export profile <name>`
func (r *ProfileRunner) Export(in Request) (*Response, error) {
Expand All @@ -242,9 +258,11 @@ func (r *ProfileRunner) Export(in Request) (*Response, error) {
}, nil
}

//////////////////////////////////////////////////////////////////////////////
// Dumper Interface
//
/*
******************************************************************************
Dumper interface
******************************************************************************
*/

// Dump implements the `dump prorfiles` command
func (r *ProfileRunner) Dump(in Request) (*Response, error) {
Expand All @@ -270,9 +288,11 @@ func (r *ProfileRunner) Dump(in Request) (*Response, error) {
}, nil
}

//////////////////////////////////////////////////////////////////////////////
// Loader Interface
//
/*
******************************************************************************
Loader interface
******************************************************************************
*/

// Load implements the `load profiles ...` command
func (r *ProfileRunner) Load(in Request) (*Response, error) {
Expand Down Expand Up @@ -318,9 +338,11 @@ func (r *ProfileRunner) Load(in Request) (*Response, error) {
}, nil
}

//////////////////////////////////////////////////////////////////////////////
// Private functions
//
/*
******************************************************************************
Private functions
******************************************************************************
*/

func (r *ProfileRunner) importProfile(in services.Profile, replace bool) error {
logger.Trace()
Expand Down
5 changes: 5 additions & 0 deletions internal/runners/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
// Proprietary and confidential

package runners

import "embed"

//go:embed templates/*
var templates embed.FS
2 changes: 1 addition & 1 deletion internal/runners/templates/accounts/describe.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Username: {{ .Username }} ({{ .Idi }})
Username: {{ .Username }} ({{ .Id }})
Email: {{ .Email }}
Provenance: {{ .Provenance }}
Currently logged in: {{ .LoggedIn }}
Expand Down
2 changes: 2 additions & 0 deletions internal/runners/templates/profiles/describe.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name: {{.Id}}
Description: {{.Description}}