Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Export command option types #686

Merged
merged 2 commits into from
Sep 9, 2020
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
8 changes: 4 additions & 4 deletions cmd/ignite/run/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (

// checkRunning can be used to skip the running check, this is used by Start and Run
// as the in-container ignite takes some time to start up and update the state
type attachOptions struct {
type AttachOptions struct {
checkRunning bool
vm *api.VM
}

func NewAttachOptions(vmMatch string) (ao *attachOptions, err error) {
ao = &attachOptions{checkRunning: true}
func NewAttachOptions(vmMatch string) (ao *AttachOptions, err error) {
ao = &AttachOptions{checkRunning: true}
ao.vm, err = getVMForMatch(vmMatch)
return
}

func Attach(ao *attachOptions) error {
func Attach(ao *AttachOptions) error {
// Check if the VM is running
if ao.checkRunning && !ao.vm.Running() {
return fmt.Errorf("VM %q is not running", ao.vm.GetUID())
Expand Down
8 changes: 4 additions & 4 deletions cmd/ignite/run/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type CPFlags struct {
IdentityFile string
}

type cpOptions struct {
type CpOptions struct {
*CPFlags
vm *api.VM
source string
Expand All @@ -48,8 +48,8 @@ const (
)

// NewCPOptions parses the command inputs and returns a copy option.
func (cf *CPFlags) NewCPOptions(source string, dest string) (co *cpOptions, err error) {
co = &cpOptions{CPFlags: cf}
func (cf *CPFlags) NewCPOptions(source string, dest string) (co *CpOptions, err error) {
co = &CpOptions{CPFlags: cf}

// Identify the direction of copy from the source and destination.
// If the source contains <file path> and destination contains
Expand Down Expand Up @@ -95,7 +95,7 @@ func (cf *CPFlags) NewCPOptions(source string, dest string) (co *cpOptions, err

// CP connects to a VM and copies files between the host and the VM based on the
// copy options.
func CP(co *cpOptions) error {
func CP(co *CpOptions) error {
// Check if the VM is running
if !co.vm.Running() {
return fmt.Errorf("VM %q is not running", co.vm.GetUID())
Expand Down
8 changes: 4 additions & 4 deletions cmd/ignite/run/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ type CreateFlags struct {
RequireName bool
}

type createOptions struct {
type CreateOptions struct {
*CreateFlags
image *api.Image
kernel *api.Kernel
}

func (cf *CreateFlags) NewCreateOptions(args []string, fs *flag.FlagSet) (*createOptions, error) {
func (cf *CreateFlags) NewCreateOptions(args []string, fs *flag.FlagSet) (*CreateOptions, error) {
// Create a new base VM and configure it by combining the component config,
// VM config file and flags.
baseVM := providers.Client.VMs().New()
Expand Down Expand Up @@ -92,7 +92,7 @@ func (cf *CreateFlags) NewCreateOptions(args []string, fs *flag.FlagSet) (*creat
return nil, err
}

co := &createOptions{CreateFlags: cf}
co := &CreateOptions{CreateFlags: cf}

// Get the image, or import it if it doesn't exist.
var err error
Expand Down Expand Up @@ -215,7 +215,7 @@ func applyVMFlagOverrides(baseVM *api.VM, cf *CreateFlags, fs *flag.FlagSet) err
return err
}

func Create(co *createOptions) (err error) {
func Create(co *CreateOptions) (err error) {
// Generate a random UID and Name
if err = metadata.SetNameAndUID(co.VM, providers.Client); err != nil {
return
Expand Down
12 changes: 6 additions & 6 deletions cmd/ignite/run/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ type ExecFlags struct {
Tty bool
}

type execOptions struct {
type ExecOptions struct {
*ExecFlags
vm *api.VM
command []string
}

// NewExecOptions constructs and returns an execOptions.
func (ef *ExecFlags) NewExecOptions(vmMatch string, command ...string) (eo *execOptions, err error) {
eo = &execOptions{
// NewExecOptions constructs and returns an ExecOptions.
func (ef *ExecFlags) NewExecOptions(vmMatch string, command ...string) (eo *ExecOptions, err error) {
eo = &ExecOptions{
ExecFlags: ef,
command: command,
}
Expand All @@ -28,7 +28,7 @@ func (ef *ExecFlags) NewExecOptions(vmMatch string, command ...string) (eo *exec
return
}

// Exec executes command in a VM based on the provided execOptions.
func Exec(eo *execOptions) error {
// Exec executes command in a VM based on the provided ExecOptions.
func Exec(eo *ExecOptions) error {
return runSSH(eo.vm, eo.IdentityFile, eo.command, eo.Tty, eo.Timeout)
}
8 changes: 4 additions & 4 deletions cmd/ignite/run/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
"github.com/weaveworks/libgitops/pkg/filter"
)

type imagesOptions struct {
type ImagesOptions struct {
allImages []*api.Image
}

func NewImagesOptions() (io *imagesOptions, err error) {
io = &imagesOptions{}
func NewImagesOptions() (io *ImagesOptions, err error) {
io = &ImagesOptions{}
io.allImages, err = providers.Client.Images().FindAll(filter.NewAllFilter())
return
}

func Images(io *imagesOptions) error {
func Images(io *ImagesOptions) error {
o := util.NewOutput()
defer o.Flush()

Expand Down
12 changes: 6 additions & 6 deletions cmd/ignite/run/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ type InspectFlags struct {
TemplateFormat string
}

type inspectOptions struct {
type InspectOptions struct {
*InspectFlags
object runtime.Object
}

// NewInspectOptions constructs and returns inspectOptions with the given kind
// NewInspectOptions constructs and returns InspectOptions with the given kind
// and object ID.
func (i *InspectFlags) NewInspectOptions(k, objectMatch string) (*inspectOptions, error) {
func (i *InspectFlags) NewInspectOptions(k, objectMatch string) (*InspectOptions, error) {
var err error
var kind runtime.Kind
io := &inspectOptions{InspectFlags: i}
io := &InspectOptions{InspectFlags: i}

switch strings.ToLower(k) {
case api.KindImage.Lower():
Expand All @@ -50,8 +50,8 @@ func (i *InspectFlags) NewInspectOptions(k, objectMatch string) (*inspectOptions
}

// Inspect renders the result of inspect in different formats based on the
// inspectOptions.
func Inspect(io *inspectOptions) error {
// InspectOptions.
func Inspect(io *InspectOptions) error {
var b []byte
var err error

Expand Down
2 changes: 1 addition & 1 deletion cmd/ignite/run/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestInspect(t *testing.T) {
t.Fatalf("failed to create test vm: %v", err)
}

iop := &inspectOptions{InspectFlags: rt.inspectFlags, object: runtime.Object(vm)}
iop := &InspectOptions{InspectFlags: rt.inspectFlags, object: runtime.Object(vm)}

// Run inspect and capture stdout.
oldStdout := os.Stdout
Expand Down
8 changes: 4 additions & 4 deletions cmd/ignite/run/kernels.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
"github.com/weaveworks/libgitops/pkg/filter"
)

type kernelsOptions struct {
type KernelsOptions struct {
allKernels []*api.Kernel
}

func NewKernelsOptions() (ko *kernelsOptions, err error) {
ko = &kernelsOptions{}
func NewKernelsOptions() (ko *KernelsOptions, err error) {
ko = &KernelsOptions{}
ko.allKernels, err = providers.Client.Kernels().FindAll(filter.NewAllFilter())
return
}

func Kernels(ko *kernelsOptions) error {
func Kernels(ko *KernelsOptions) error {
o := util.NewOutput()
defer o.Flush()

Expand Down
8 changes: 4 additions & 4 deletions cmd/ignite/run/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"github.com/weaveworks/ignite/pkg/util"
)

type logsOptions struct {
type LogsOptions struct {
vm *api.VM
}

func NewLogsOptions(vmMatch string) (lo *logsOptions, err error) {
lo = &logsOptions{}
func NewLogsOptions(vmMatch string) (lo *LogsOptions, err error) {
lo = &LogsOptions{}
lo.vm, err = getVMForMatch(vmMatch)
return
}

func Logs(lo *logsOptions) error {
func Logs(lo *LogsOptions) error {
// Check if the VM is running
if !lo.vm.Running() {
return fmt.Errorf("VM %q is not running", lo.vm.GetUID())
Expand Down
12 changes: 6 additions & 6 deletions cmd/ignite/run/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ type PsFlags struct {
TemplateFormat string
}

type psOptions struct {
type PsOptions struct {
*PsFlags
allVMs []*api.VM
}

// NewPsOptions constructs and returns psOptions.
func (pf *PsFlags) NewPsOptions() (po *psOptions, err error) {
po = &psOptions{PsFlags: pf}
// NewPsOptions constructs and returns PsOptions.
func (pf *PsFlags) NewPsOptions() (po *PsOptions, err error) {
po = &PsOptions{PsFlags: pf}
po.allVMs, err = providers.Client.VMs().FindAll(filter.NewVMFilterAll("", po.All))
return
}

// Ps filters and renders the VMs based on the psOptions.
func Ps(po *psOptions) error {
// Ps filters and renders the VMs based on the PsOptions.
func Ps(po *PsOptions) error {
var filters *filter.MultipleMetaFilter
var err error
var filtering bool
Expand Down
2 changes: 1 addition & 1 deletion cmd/ignite/run/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestPs(t *testing.T) {
vms = append(vms, vm)
}

psop := &psOptions{PsFlags: rt.psFlags, allVMs: vms}
psop := &PsOptions{PsFlags: rt.psFlags, allVMs: vms}

// Run vm list and capture stdout.
oldStdout := os.Stdout
Expand Down
12 changes: 6 additions & 6 deletions cmd/ignite/run/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type RmFlags struct {
ConfigFile string
}

type rmOptions struct {
type RmOptions struct {
*RmFlags
vms []*api.VM
}

// NewRmOptions creates and returns rmOptions with all the flags and VMs to be
// NewRmOptions creates and returns RmOptions with all the flags and VMs to be
// removed.
func (rf *RmFlags) NewRmOptions(vmMatches []string) (*rmOptions, error) {
ro := &rmOptions{RmFlags: rf}
func (rf *RmFlags) NewRmOptions(vmMatches []string) (*RmOptions, error) {
ro := &RmOptions{RmFlags: rf}

// If config file is provided, use it to find the VM to be removed.
if len(rf.ConfigFile) != 0 {
Expand Down Expand Up @@ -52,8 +52,8 @@ func (rf *RmFlags) NewRmOptions(vmMatches []string) (*rmOptions, error) {
return ro, err
}

// Rm removes VMs based on rmOptions.
func Rm(ro *rmOptions) error {
// Rm removes VMs based on RmOptions.
func Rm(ro *RmOptions) error {
for _, vm := range ro.vms {
// If the VM is running, but we haven't enabled force-mode, return an error
if vm.Running() && !ro.Force {
Expand Down
10 changes: 5 additions & 5 deletions cmd/ignite/run/rmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ type RmiFlags struct {
Force bool
}

type rmiOptions struct {
type RmiOptions struct {
*RmiFlags
images []*api.Image
allVMs []*api.VM
}

func (rf *RmiFlags) NewRmiOptions(imageMatches []string) (*rmiOptions, error) {
ro := &rmiOptions{RmiFlags: rf}
func (rf *RmiFlags) NewRmiOptions(imageMatches []string) (*RmiOptions, error) {
ro := &RmiOptions{RmiFlags: rf}

for _, match := range imageMatches {
if image, err := providers.Client.Images().Find(filter.NewIDNameFilter(match)); err == nil {
Expand All @@ -41,7 +41,7 @@ func (rf *RmiFlags) NewRmiOptions(imageMatches []string) (*rmiOptions, error) {
return ro, nil
}

func Rmi(ro *rmiOptions) error {
func Rmi(ro *RmiOptions) error {
for _, image := range ro.images {
for _, vm := range ro.allVMs {
imageUID, err := lookup.ImageUIDForVM(vm, providers.Client)
Expand All @@ -54,7 +54,7 @@ func Rmi(ro *rmiOptions) error {
if imageUID == image.GetUID() {
if ro.Force {
// Force-kill and remove the VM used by this image
if err := Rm(&rmOptions{
if err := Rm(&RmOptions{
&RmFlags{Force: true},
[]*api.VM{vm},
}); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/ignite/run/rmk.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ type RmkFlags struct {
Force bool
}

type rmkOptions struct {
type RmkOptions struct {
*RmkFlags
kernels []*api.Kernel
allVMs []*api.VM
}

func (rf *RmkFlags) NewRmkOptions(kernelMatches []string) (*rmkOptions, error) {
ro := &rmkOptions{RmkFlags: rf}
func (rf *RmkFlags) NewRmkOptions(kernelMatches []string) (*RmkOptions, error) {
ro := &RmkOptions{RmkFlags: rf}

for _, match := range kernelMatches {
if kernel, err := providers.Client.Kernels().Find(filter.NewIDNameFilter(match)); err == nil {
Expand All @@ -41,7 +41,7 @@ func (rf *RmkFlags) NewRmkOptions(kernelMatches []string) (*rmkOptions, error) {
return ro, nil
}

func Rmk(ro *rmkOptions) error {
func Rmk(ro *RmkOptions) error {
for _, kernel := range ro.kernels {
for _, vm := range ro.allVMs {
kernelUID, err := lookup.KernelUIDForVM(vm, providers.Client)
Expand All @@ -54,7 +54,7 @@ func Rmk(ro *rmkOptions) error {
if kernelUID == kernel.GetUID() {
if ro.Force {
// Force-kill and remove the VM used by this kernel
if err := Rm(&rmOptions{
if err := Rm(&RmOptions{
&RmFlags{Force: true},
[]*api.VM{vm},
}); err != nil {
Expand Down
Loading