diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..475d9c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +# build output +output/ diff --git a/cmd/root.go b/cmd/root.go index 54b1289..226fb55 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,8 +15,8 @@ var rootCmd = &cobra.Command{ Use: "cmdb", Short: "A cli based CMDB", Long: `A cli based CMDB. - You can manage subnets, single ip addresses within those, and the corresponding A records. - IPV6-Support will follow.`, +You can manage subnets, single ip addresses within those, and the corresponding A records. +IPV6-Support will follow.`, // Uncomment the following line if your bare application // has an action associated with it: // Run: func(cmd *cobra.Command, args []string) { }, diff --git a/cmd/subnet-add.go b/cmd/subnet-add.go index 0156d7b..41c22f8 100644 --- a/cmd/subnet-add.go +++ b/cmd/subnet-add.go @@ -13,13 +13,8 @@ import ( // addCmd represents the add command var subnetaddCmd = &cobra.Command{ Use: "add [subnet] [vlan]", - 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.`, + Short: "Add a new subnet", + Long: `Add a new subnet`, Run: func(cmd *cobra.Command, args []string) { var subnet string var vlanid string diff --git a/cmd/subnet-delete.go b/cmd/subnet-delete.go new file mode 100644 index 0000000..5644b44 --- /dev/null +++ b/cmd/subnet-delete.go @@ -0,0 +1,47 @@ +/* +Copyright © 2023 Laura Kalb +*/ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +// deleteCmd represents the delete command +var subnetdeleteCmd = &cobra.Command{ + Use: "delete", + Short: "delete subnet", + Long: `Delete a subnet from the cmdb.`, + Run: func(cmd *cobra.Command, args []string) { + if len(args) < 1 { + fmt.Println("Error: Too few arguments!") + fmt.Print("Usage:\n cmdb subnet delete [subnet]") + os.Exit(1) + } + if len(args) > 1 { + fmt.Println("Error: Too many arguments!") + fmt.Print("Usage:\n cmdb subnet delete [subnet]") + os.Exit(1) + } + subnet := args[0] + + fmt.Printf("Deleting %v\n", subnet) + }, +} + +func init() { + subnetCmd.AddCommand(subnetdeleteCmd) + + // 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") +} diff --git a/cmd/subnet-list.go b/cmd/subnet-list.go new file mode 100644 index 0000000..5246cca --- /dev/null +++ b/cmd/subnet-list.go @@ -0,0 +1,40 @@ +/* +Copyright © 2023 Laura Kalb + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// listCmd represents the list command +var subnetlistCmd = &cobra.Command{ + Use: "list", + 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) { + fmt.Println("subnet list called") + }, +} + +func init() { + subnetCmd.AddCommand(subnetlistCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // listCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/subnet-show.go b/cmd/subnet-show.go new file mode 100644 index 0000000..61fbadb --- /dev/null +++ b/cmd/subnet-show.go @@ -0,0 +1,40 @@ +/* +Copyright © 2023 Laura Kalb + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// showCmd represents the show command +var subnetshowCmd = &cobra.Command{ + Use: "show", + 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) { + fmt.Println("subnet show called") + }, +} + +func init() { + subnetCmd.AddCommand(subnetshowCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // showCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // showCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/lib/storage.go b/lib/storage.go new file mode 100644 index 0000000..8c1acc3 --- /dev/null +++ b/lib/storage.go @@ -0,0 +1,5 @@ +/* +Copyright © 2023 Laura Kalb +*/ + +package storage