mirror of
https://gitea.elkins.co/Networking/ccl.git
synced 2025-03-09 12:41:40 -05:00
Add rm
command
This commit is contained in:
parent
53272b0da9
commit
25297fc604
59
cmd/rm.go
Normal file
59
cmd/rm.go
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright © 2022 Joel D. Elkins <joel@elkins.co>
|
||||
|
||||
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 cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// rmCmd represents the rm command
|
||||
var rmCmd = &cobra.Command{
|
||||
Use: "rm",
|
||||
Aliases: []string{"remove", "delete"},
|
||||
Short: "Remove container definitions",
|
||||
ValidArgsFunction: validNouns,
|
||||
Args: cobra.OnlyValidArgs,
|
||||
Long: `Remove defined containers or categories if they have been created.
|
||||
If running, they will first be stopped.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
for _, c := range conts {
|
||||
fmt.Fprintln(output, "REMOVE", c.Name)
|
||||
for _, cmd := range c.DestroyCommands() {
|
||||
if err := cmd.Execute(output, fake); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"container": c.Name,
|
||||
"cmd": cmd,
|
||||
}).Errorln("Remove failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(rmCmd)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user