add subnet commands

This commit is contained in:
Adora Laura Kalb 2023-03-11 13:49:35 +01:00
parent 111b90e91e
commit 8f462aa520
7 changed files with 160 additions and 9 deletions

24
.gitignore vendored Normal file
View file

@ -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/

View file

@ -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) { },

View file

@ -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

47
cmd/subnet-delete.go Normal file
View file

@ -0,0 +1,47 @@
/*
Copyright © 2023 Laura Kalb <dev@lauka.net>
*/
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")
}

40
cmd/subnet-list.go Normal file
View file

@ -0,0 +1,40 @@
/*
Copyright © 2023 Laura Kalb <dev@lauka.net>
*/
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")
}

40
cmd/subnet-show.go Normal file
View file

@ -0,0 +1,40 @@
/*
Copyright © 2023 Laura Kalb <dev@lauka.net>
*/
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")
}

5
lib/storage.go Normal file
View file

@ -0,0 +1,5 @@
/*
Copyright © 2023 Laura Kalb <dev@lauka.net>
*/
package storage