summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorAlex Goodman <wagoodman@gmail.com>2018-10-01 21:50:05 -0400
committerAlex Goodman <wagoodman@gmail.com>2018-10-01 21:50:05 -0400
commit3a9796619c235e99cc7aad288f6e83f0cd448b3a (patch)
tree6e34e4794c1dde6fc93bab6c5a864cec308768a4 /cmd
parent2a82632e57b4c045a877bb8b3d2cc2b2ad80f507 (diff)
renamed to dive; use cobra; rm dep; imagehistory fix
Diffstat (limited to 'cmd')
-rw-r--r--cmd/analyze.go39
-rw-r--r--cmd/build.go51
-rw-r--r--cmd/die/main.go36
-rw-r--r--cmd/root.go89
4 files changed, 179 insertions, 36 deletions
diff --git a/cmd/analyze.go b/cmd/analyze.go
new file mode 100644
index 0000000..88745e3
--- /dev/null
+++ b/cmd/analyze.go
@@ -0,0 +1,39 @@
+// Copyright © 2018 Alex Goodman
+//
+// 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 (
+ "github.com/spf13/cobra"
+ "fmt"
+ "os"
+ "github.com/wagoodman/dive/image"
+ "github.com/wagoodman/dive/ui"
+)
+
+func analyze(cmd *cobra.Command, args []string) {
+ userImage := args[0]
+ if userImage == "" {
+ fmt.Println("No image argument given")
+ os.Exit(1)
+ }
+ manifest, refTrees := image.InitializeData(userImage)
+ ui.Run(manifest, refTrees)
+} \ No newline at end of file
diff --git a/cmd/build.go b/cmd/build.go
new file mode 100644
index 0000000..99ebdd8
--- /dev/null
+++ b/cmd/build.go
@@ -0,0 +1,51 @@
+// Copyright © 2018 Alex Goodman
+//
+// 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"
+
+ "github.com/spf13/cobra"
+)
+
+// buildCmd represents the build command
+var buildCmd = &cobra.Command{
+ Use: "build",
+ Short: "Build and analyze a docker image",
+ Long: `Build and analyze a docker image`,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("build called")
+ },
+}
+
+func init() {
+ rootCmd.AddCommand(buildCmd)
+
+ // Here you will define your flags and configuration settings.
+
+ // Cobra supports Persistent Flags which will work for this command
+ // and all subcommands, e.g.:
+ // buildCmd.PersistentFlags().String("foo", "", "A help for foo")
+
+ // Cobra supports local flags which will only run when this command
+ // is called directly, e.g.:
+ // buildCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
+}
diff --git a/cmd/die/main.go b/cmd/die/main.go
deleted file mode 100644
index fa9b019..0000000
--- a/cmd/die/main.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package main
-
-import (
- "fmt"
- "log"
- "os"
-
- "github.com/urfave/cli"
- "github.com/wagoodman/docker-image-explorer/image"
- "github.com/wagoodman/docker-image-explorer/ui"
-)
-
-const name = "die"
-const version = "v0.0.0"
-const author = "wagoodman"
-
-func main() {
- app := cli.NewApp()
- app.Name = "die"
- app.Usage = "Explore your docker images"
- app.Action = func(c *cli.Context) error {
- userImage := c.Args().Get(0)
- if userImage == "" {
- fmt.Println("No image argument given")
- os.Exit(1)
- }
- manifest, refTrees := image.InitializeData(userImage)
- ui.Run(manifest, refTrees)
- return nil
- }
-
- err := app.Run(os.Args)
- if err != nil {
- log.Fatal(err)
- }
-}
diff --git a/cmd/root.go b/cmd/root.go
new file mode 100644
index 0000000..91d46a7
--- /dev/null
+++ b/cmd/root.go
@@ -0,0 +1,89 @@
+// Copyright © 2018 Alex Goodman
+//
+// 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"
+ "os"
+
+ homedir "github.com/mitchellh/go-homedir"
+ "github.com/spf13/cobra"
+ "github.com/spf13/viper"
+)
+
+var cfgFile string
+
+// rootCmd represents the base command when called without any subcommands
+var rootCmd = &cobra.Command{
+ Use: "dive",
+ Short: "Docker Image Visualizer & Explorer",
+ Long: `Docker Image Visualizer & Explorer`,
+ Args: cobra.ExactArgs(1),
+ Run: analyze,
+}
+
+// Execute adds all child commands to the root command and sets flags appropriately.
+// This is called by main.main(). It only needs to happen once to the rootCmd.
+func Execute() {
+ if err := rootCmd.Execute(); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+}
+
+func init() {
+ cobra.OnInitialize(initConfig)
+
+ // Here you will define your flags and configuration settings.
+ // Cobra supports persistent flags, which, if defined here,
+ // will be global for your application.
+ rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.dive.yaml)")
+
+ // Cobra also supports local flags, which will only run
+ // when this action is called directly.
+ rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
+}
+
+// initConfig reads in config file and ENV variables if set.
+func initConfig() {
+ if cfgFile != "" {
+ // Use config file from the flag.
+ viper.SetConfigFile(cfgFile)
+ } else {
+ // Find home directory.
+ home, err := homedir.Dir()
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ // Search config in home directory with name ".dive" (without extension).
+ viper.AddConfigPath(home)
+ viper.SetConfigName(".dive")
+ }
+
+ viper.AutomaticEnv() // read in environment variables that match
+
+ // If a config file is found, read it in.
+ if err := viper.ReadInConfig(); err == nil {
+ fmt.Println("Using config file:", viper.ConfigFileUsed())
+ }
+}