42 lines
915 B
Go
42 lines
915 B
Go
package cmd
|
|
|
|
import (
|
|
"git.towk2.me/towk/makeshift/pkg/service"
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var initCmd = &cobra.Command{
|
|
Use: "init",
|
|
Example: `
|
|
# create default files and directories at specified root path
|
|
# (must be set with positional argument)
|
|
makeshift init $MAKESHIFT_ROOT
|
|
`,
|
|
Args: cobra.ExactArgs(1),
|
|
Short: "Initialize directory with default files",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
var (
|
|
server *service.Service
|
|
err error
|
|
)
|
|
|
|
// create the server root files and directories
|
|
server = service.New()
|
|
server.RootPath = args[0]
|
|
err = server.Init()
|
|
if err != nil {
|
|
log.Error().Err(err).
|
|
Str("root", server.RootPath).
|
|
Msg("failed to initialize server root")
|
|
return
|
|
}
|
|
log.Debug().
|
|
Str("root", server.RootPath).
|
|
Msg("initialize makeshift files at root path")
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(initCmd)
|
|
}
|