mirror of
https://codeberg.org/lauralani/ipam.git
synced 2024-11-24 04:30:02 +01:00
add subnet commands
This commit is contained in:
parent
111b90e91e
commit
8f462aa520
7 changed files with 160 additions and 9 deletions
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal 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/
|
|
@ -13,13 +13,8 @@ import (
|
||||||
// addCmd represents the add command
|
// addCmd represents the add command
|
||||||
var subnetaddCmd = &cobra.Command{
|
var subnetaddCmd = &cobra.Command{
|
||||||
Use: "add [subnet] [vlan]",
|
Use: "add [subnet] [vlan]",
|
||||||
Short: "A brief description of your command",
|
Short: "Add a new subnet",
|
||||||
Long: `A longer description that spans multiple lines and likely contains examples
|
Long: `Add a new subnet`,
|
||||||
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) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var subnet string
|
var subnet string
|
||||||
var vlanid string
|
var vlanid string
|
||||||
|
|
47
cmd/subnet-delete.go
Normal file
47
cmd/subnet-delete.go
Normal 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
40
cmd/subnet-list.go
Normal 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
40
cmd/subnet-show.go
Normal 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
5
lib/storage.go
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
/*
|
||||||
|
Copyright © 2023 Laura Kalb <dev@lauka.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
package storage
|
Loading…
Reference in a new issue