Skip to content

Commit

Permalink
allow rmi to follow docker style command
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed Nov 28, 2020
1 parent 2654731 commit f56934e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 18 deletions.
18 changes: 0 additions & 18 deletions command/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
package command

import (
"errors"
"fmt"
"github.com/mhewedy/vermin/images"
"os"
Expand Down Expand Up @@ -52,25 +51,8 @@ $ vermin create <image>
},
}

var imageRmCmd = &cobra.Command{
Use: "rm",
Short: "Remove cached/committed images",
Long: "Remove cached/committed images",
RunE: func(cmd *cobra.Command, args []string) error {
return images.Remove(args[0])
},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("image required")
}
return nil
},
ValidArgsFunction: listImages,
}

func init() {
rootCmd.AddCommand(imagesCmd)
imagesCmd.AddCommand(imageRmCmd)

// Here you will define your flags and configuration settings.

Expand Down
63 changes: 63 additions & 0 deletions command/remove_image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package command

import (
"errors"
"fmt"
"github.com/mhewedy/vermin/images"
"github.com/spf13/cobra"
"os"
)

// removeImageCmd represents the remove image command
var removeImageCmd = &cobra.Command{
Use: "rmi",
Short: "Remove one or more Image",
Long: `Remove one or more Image`,
Run: func(cmd *cobra.Command, args []string) {
for _, vmName := range args {
//force, _ := cmd.Flags().GetBool("force")

err := images.Remove(vmName)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("image required")
}
return nil
},
ValidArgsFunction: listImages,
}

func init() {
rootCmd.AddCommand(removeImageCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// removeCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
//removeCmd.Flags().BoolP("force", "f", false, "force remove running VM")
}

0 comments on commit f56934e

Please sign in to comment.