add subcommands

pull/227/head
iwilltry42 5 years ago
parent dcda1bbeec
commit 95c28f298c
  1. 36
      cmd/create/create.go
  2. 47
      cmd/create/createCluster.go
  3. 45
      cmd/create/createNode.go
  4. 48
      cmd/delete/delete.go
  5. 47
      cmd/delete/deleteCluster.go
  6. 47
      cmd/delete/deleteNode.go
  7. 49
      cmd/get/get.go
  8. 47
      cmd/get/getCluster.go
  9. 47
      cmd/get/getKubeconfig.go
  10. 47
      cmd/get/getNode.go
  11. 9
      cmd/root.go
  12. 20
      internal/types.go

@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd
package create
import (
log "github.com/sirupsen/logrus"
@ -27,26 +27,22 @@ import (
"github.com/spf13/cobra"
)
// createCmd represents the create command
var createCmd = &cobra.Command{
Use: "create",
Short: "Create a resource.",
Long: `Create a resource.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("create called")
},
}
func init() {
rootCmd.AddCommand(createCmd)
// NewCmdCreate returns a new cobra command
func NewCmdCreate() *cobra.Command {
// Here you will define your flags and configuration settings.
// create new cobra command
cmd := &cobra.Command{
Use: "create",
Short: "Create a resource.",
Long: `Create a resource.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("create called")
},
}
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// createCmd.PersistentFlags().String("foo", "", "A help for foo")
// add subcommands
cmd.AddCommand(NewCmdCreateCluster())
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// createCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// done
return cmd
}

@ -0,0 +1,47 @@
/*
Copyright © 2019 Thorsten Klein <iwilltry42@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package create
import (
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
// NewCmdCreateCluster returns a new cobra command
func NewCmdCreateCluster() *cobra.Command {
// create new command
cmd := &cobra.Command{
Use: "cluster",
Short: "Create a new k3s cluster in docker",
Long: `Create a new k3s cluster with containerized nodes (k3s in docker).`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("create cluster called")
},
}
// add subcommands
// done
return cmd
}

@ -0,0 +1,45 @@
/*
Copyright © 2019 Thorsten Klein <iwilltry42@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package create
import (
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
// NewCmdCreateNode returns a new cobra command
func NewCmdCreateNode() *cobra.Command {
// create new command
cmd := &cobra.Command{
Use: "node",
Short: "Create a new k3s node in docker",
Long: `Create a new containerized k3s node (k3s in docker).`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("create node called")
},
}
// done
return cmd
}

@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd
package delete
import (
log "github.com/sirupsen/logrus"
@ -27,31 +27,23 @@ import (
"github.com/spf13/cobra"
)
// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("delete called")
},
}
func init() {
rootCmd.AddCommand(deleteCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// deleteCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// deleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// NewCmdDelete returns a new cobra command
func NewCmdDelete() *cobra.Command {
// create new cobra command
cmd := &cobra.Command{
Use: "delete",
Short: "Delete a resource.",
Long: `Delete a resource.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("delete called")
},
}
// add subcommands
cmd.AddCommand(NewCmdDeleteCluster())
cmd.AddCommand(NewCmdDeleteNode())
// done
return cmd
}

@ -0,0 +1,47 @@
/*
Copyright © 2019 Thorsten Klein <iwilltry42@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package delete
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// NewCmdDeleteCluster returns a new cobra command
func NewCmdDeleteCluster() *cobra.Command {
// create new cobra command
cmd := &cobra.Command{
Use: "cluster",
Short: "Delete a cluster.",
Long: `Delete a cluster.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("delete cluster called")
},
}
// add subcommands
// done
return cmd
}

@ -0,0 +1,47 @@
/*
Copyright © 2019 Thorsten Klein <iwilltry42@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package delete
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// NewCmdDeleteNode returns a new cobra command
func NewCmdDeleteNode() *cobra.Command {
// create new cobra command
cmd := &cobra.Command{
Use: "node",
Short: "Delete a node.",
Long: `Delete a node.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("delete node called")
},
}
// add subcommands
// done
return cmd
}

@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd
package delete
import (
log "github.com/sirupsen/logrus"
@ -27,31 +27,24 @@ import (
"github.com/spf13/cobra"
)
// getCmd represents the get command
var getCmd = &cobra.Command{
Use: "get",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("get called")
},
}
func init() {
rootCmd.AddCommand(getCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// getCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// getCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// NewCmdGet returns a new cobra command
func NewCmdGet() *cobra.Command {
// create new cobra command
cmd := &cobra.Command{
Use: "get",
Short: "Get a resource.",
Long: `Get a resource.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("get called")
},
}
// add subcommands
cmd.AddCommand(NewCmdGetCluster())
cmd.AddCommand(NewCmdGetNode())
cmd.AddCommand(NewCmdGetKubeconfig())
// done
return cmd
}

@ -0,0 +1,47 @@
/*
Copyright © 2019 Thorsten Klein <iwilltry42@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package get
import (
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
// NewCmdGetCluster returns a new cobra command
func NewCmdGetCluster() *cobra.Command {
// create new command
cmd := &cobra.Command{
Use: "cluster",
Short: "Get cluster",
Long: `Get cluster.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("get cluster called")
},
}
// add subcommands
// done
return cmd
}

@ -0,0 +1,47 @@
/*
Copyright © 2019 Thorsten Klein <iwilltry42@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package get
import (
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
// NewCmdGetKubeconfig returns a new cobra command
func NewCmdGetKubeconfig() *cobra.Command {
// create new command
cmd := &cobra.Command{
Use: "kubeconfig",
Short: "Get kubeconfig",
Long: `Get kubeconfig.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("get kubeconfig called")
},
}
// add subcommands
// done
return cmd
}

@ -0,0 +1,47 @@
/*
Copyright © 2019 Thorsten Klein <iwilltry42@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package get
import (
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
// NewCmdGetNode returns a new cobra command
func NewCmdGetNode() *cobra.Command {
// create new command
cmd := &cobra.Command{
Use: "node",
Short: "Get node",
Long: `Get node.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("get node called")
},
}
// add subcommands
// done
return cmd
}

@ -26,6 +26,10 @@ import (
"strings"
"github.com/spf13/cobra"
"github.com/rancher/k3d/cmd/get"
"github.com/rancher/k3d/cmd/create"
"github.com/rancher/k3d/cmd/delete"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
@ -68,6 +72,11 @@ func init() {
// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("nope", "n", false, "nope description")
// add subcommands
rootCmd.AddCommand(create.NewCmdCreate())
rootCmd.AddCommand(delete.NewCmdDelete())
rootCmd.AddCommand(get.NewCmdGet())
}
// initConfig reads in config file and ENV variables if set.

@ -0,0 +1,20 @@
package types
// Cluster describes a k3d cluster
type Cluster struct {
Name string
Network string
Nodes []Node
}
// Node describes a k3d node
type Node struct {
Name string
Role string
Image string
Volumes []string
Env []string
Args []string
Ports []string
Restart bool
}
Loading…
Cancel
Save