Skip to content

Commit

Permalink
feat(file_templates/gitignore): Add gitignore template
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejsika committed Aug 3, 2021
1 parent 8c2ea8f commit 11614ef
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
_ "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/file_templates/gitignore"
_ "github.com/sikalabs/slut/cmd/mysql"
_ "github.com/sikalabs/slut/cmd/mysql/create"
_ "github.com/sikalabs/slut/cmd/mysql/drop"
Expand Down
34 changes: 34 additions & 0 deletions cmd/file_templates/gitignore/gitignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package gitignore

import (
file_templates_cmd "github.com/sikalabs/slut/cmd/file_templates"
"github.com/sikalabs/slut/file_templates/gitignore"

"github.com/spf13/cobra"
)

var FlagTerraform bool

var Cmd = &cobra.Command{
Use: "gitignore",
Short: "Create basic gitignore",
Aliases: []string{"gi"},
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
content := gitignore.GitignoreBase
if FlagTerraform {
content += "\n" + gitignore.GitignoreTerraform
}
gitignore.CreateGitignore(content)
},
}

func init() {
file_templates_cmd.Cmd.AddCommand(Cmd)
Cmd.Flags().BoolVar(
&FlagTerraform,
"terraform",
false,
"Add Terraform part",
)
}
30 changes: 30 additions & 0 deletions file_templates/gitignore/gitignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gitignore

import "io/ioutil"

var GitignoreBase = `# Mac
.DS_Store
# Editor
.vscode
.idea
# Generic
*.log
*.backup
`

var GitignoreTerraform = `# Terraform
.terraform
*.tfstate
.terraform.tfstate.lock.info
*.tfvars
!*.EXAMPLE.tfvars
`

func CreateGitignore(content string) {
err := ioutil.WriteFile(".gitignore", []byte(content), 0644)
if err != nil {
panic(err)
}
}

0 comments on commit 11614ef

Please sign in to comment.