Skip to content

Commit

Permalink
Add deps init command
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Oct 1, 2019
1 parent 67c698b commit 724e979
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cmd/deps/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"
"io/ioutil"
"os"

"github.com/dropseed/deps/internal/output"

"github.com/dropseed/deps/internal/config"
"github.com/spf13/cobra"
)

var initCmd = &cobra.Command{
Use: "init",
Short: "Create a deps config in the current",
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.InferredConfigFromDir(".")
if err != nil {
printErrAndExitFailure(err)
}
inferred, err := cfg.DumpYAML()
if err != nil {
printErrAndExitFailure(err)
}

filename := config.DefaultFilenames[0]

if _, err := os.Stat(filename); !os.IsNotExist(err) {
printErrAndExitFailure(fmt.Errorf("%s already exists!", filename))
}

fmt.Printf("Generating config...\n\n%s\n", inferred)

err = ioutil.WriteFile(filename, []byte(inferred), 0644)
if err != nil {
printErrAndExitFailure(err)
}
output.Success("✔ saved as %s", filename)
},
}

func init() {
rootCmd.AddCommand(initCmd)
}

0 comments on commit 724e979

Please sign in to comment.