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
40 changes: 21 additions & 19 deletions cli/cmd/compute.go → cli/cmd/compute/compute.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package compute

import (
"encoding/json"
Expand All @@ -9,10 +9,23 @@ import (

docker "github.com/fsouza/go-dockerclient"
"github.com/spf13/cobra"

)

const stateFile = "compute.json"

func init() {
// Load saved instances
loadInstances()

// Add subcommands to the compute command
ComputeCmd.AddCommand(createCmd)
ComputeCmd.AddCommand(listCmd)
ComputeCmd.AddCommand(startCmd)
ComputeCmd.AddCommand(enterCmd)
ComputeCmd.AddCommand(stopCmd)
ComputeCmd.AddCommand(deleteCmd)
}
// Instance represents a compute instance with its configuration and status
type Instance struct {
ID string `json:"id"`
Expand All @@ -37,26 +50,15 @@ var (
)

// Root command for compute operations
var computeCmd = &cobra.Command{
Use: "compute",
Short: "Manage compute resources with Docker",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
var ComputeCmd = &cobra.Command{
Use: "compute",
Short: "Manage compute resources",
Long: "The compute command allows you to manage compute resources like VMs, containers, etc.",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func init() {
rootCmd.AddCommand(computeCmd)
loadInstances()

// Add subcommands to the compute command
computeCmd.AddCommand(createCmd)
computeCmd.AddCommand(listCmd)
computeCmd.AddCommand(startCmd)
computeCmd.AddCommand(enterCmd)
computeCmd.AddCommand(stopCmd)
computeCmd.AddCommand(deleteCmd)
}

// saveInstances saves the current state of instances to a JSON file
func saveInstances() {
Expand Down
26 changes: 13 additions & 13 deletions cli/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ var configCmd = &cobra.Command{
}

func init() {
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
// Set the path to the config file in the user's home directory
configFile = filepath.Join(home, ".homecloud_config.json")

// Add subcommands to the config command
configCmd.AddCommand(setConfigCmd)
configCmd.AddCommand(getConfigCmd)

// Add the config command to the root command
rootCmd.AddCommand(configCmd)
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
// Set the path to the config file in the user's home directory
configFile = filepath.Join(home, ".homecloud_config.json")

// Add subcommands to the config command
configCmd.AddCommand(setConfigCmd)
configCmd.AddCommand(getConfigCmd)

// Add the config command to the RootCmd
RootCmd.AddCommand(configCmd) // Use RootCmd here
}
32 changes: 20 additions & 12 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package cmd

import (
"fmt"
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/cobra"
"github.com/drk1rd/homecloud/cli/cmd/compute"
)

var rootCmd = &cobra.Command{
Use: "homecloud",
Short: "HomeCloud CLI for managing self-hosted cloud services",
Long: `HomeCloud CLI provides tools to deploy, manage, and monitor
// RootCmd is the base command for the CLI, exported for use in other modules.
var RootCmd = &cobra.Command{
Use: "homecloud",
Short: "HomeCloud CLI for managing self-hosted cloud services",
Long: `HomeCloud CLI provides tools to deploy, manage, and monitor
self-hosted cloud infrastructure.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Welcome to HomeCloud CLI!")
},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Welcome to HomeCloud CLI!")
},
}

// Execute runs the root command, entry point for the CLI.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
}
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
}
}

// Register all individual comments here.
func init() {
RootCmd.AddCommand(compute.ComputeCmd)
}
Loading