From d2fa6e505332cd3b94e96fe33b6eebef6917fd45 Mon Sep 17 00:00:00 2001 From: Ondrej Sika Date: Tue, 3 Aug 2021 20:17:04 +0200 Subject: [PATCH] feat(file_templates): Add filetemplates module for easy bootsrapping of common files (now editorconfig only) --- cmd/cmd.go | 2 ++ .../editorconfig/editorconfig.go | 22 ++++++++++++++++ cmd/file_templates/file_templates.go | 16 ++++++++++++ file_templates/editorconfig/editorconfig.go | 25 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 cmd/file_templates/editorconfig/editorconfig.go create mode 100644 cmd/file_templates/file_templates.go create mode 100644 file_templates/editorconfig/editorconfig.go diff --git a/cmd/cmd.go b/cmd/cmd.go index a371759f..e8f86720 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -4,6 +4,8 @@ import ( _ "github.com/sikalabs/slut/cmd/expand" _ "github.com/sikalabs/slut/cmd/expand/file" _ "github.com/sikalabs/slut/cmd/expand/string" + _ "github.com/sikalabs/slut/cmd/file_templates" + _ "github.com/sikalabs/slut/cmd/file_templates/editorconfig" _ "github.com/sikalabs/slut/cmd/mysql" _ "github.com/sikalabs/slut/cmd/mysql/create" _ "github.com/sikalabs/slut/cmd/mysql/drop" diff --git a/cmd/file_templates/editorconfig/editorconfig.go b/cmd/file_templates/editorconfig/editorconfig.go new file mode 100644 index 00000000..d94638a2 --- /dev/null +++ b/cmd/file_templates/editorconfig/editorconfig.go @@ -0,0 +1,22 @@ +package editorconfig + +import ( + file_templates_cmd "github.com/sikalabs/slut/cmd/file_templates" + "github.com/sikalabs/slut/file_templates/editorconfig" + + "github.com/spf13/cobra" +) + +var Cmd = &cobra.Command{ + Use: "editorconfig", + Short: "Create basic editorconfig", + Aliases: []string{"ec"}, + Args: cobra.NoArgs, + Run: func(c *cobra.Command, args []string) { + editorconfig.CreateEditorconfig() + }, +} + +func init() { + file_templates_cmd.Cmd.AddCommand(Cmd) +} diff --git a/cmd/file_templates/file_templates.go b/cmd/file_templates/file_templates.go new file mode 100644 index 00000000..4f391b4a --- /dev/null +++ b/cmd/file_templates/file_templates.go @@ -0,0 +1,16 @@ +package file_templates + +import ( + "github.com/sikalabs/slut/cmd/root" + "github.com/spf13/cobra" +) + +var Cmd = &cobra.Command{ + Use: "file-templates", + Short: "Create common files from templates", + Aliases: []string{"ft"}, +} + +func init() { + root.RootCmd.AddCommand(Cmd) +} diff --git a/file_templates/editorconfig/editorconfig.go b/file_templates/editorconfig/editorconfig.go new file mode 100644 index 00000000..0a7d661d --- /dev/null +++ b/file_templates/editorconfig/editorconfig.go @@ -0,0 +1,25 @@ +package editorconfig + +import "io/ioutil" + +func CreateEditorconfig() { + content := []byte(` +root = true +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf +max_line_length = off +[Makefile] +indent_style = tab +[*.go] +indent_style = tab +`) + err := ioutil.WriteFile(".editorconfig", content, 0644) + if err != nil { + panic(err) + } +}