Skip to content

Commit

Permalink
added golang template
Browse files Browse the repository at this point in the history
  • Loading branch information
moeenn committed Jul 20, 2024
1 parent db450fe commit 5f47692
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Projects
A portable CLI tool for initializing programming projects from pre-defined templates. This tools is written in GoLang and doesn't have any 3rd-party dependencies.
A portable CLI tool for initializing programming projects from pre-defined templates. This tools is written in GoLang and doesn't have any 3rd-party dependencies.


### Inspiration
Golang's tooling is fantastic. It is simple and doesn't require any additional setup for testing, formatting etc. It would be nice if we could replicate a similar experience with other programming languages. Hence, this project was born.


### Installation
Expand Down Expand Up @@ -31,7 +35,7 @@ Usage of projects:
-name string
Name of project being initialized (default "sandbox")
-template string
Project template to use (default "cpp-cmake")
Project template to use (default "go")
```

### Available templates
Expand All @@ -40,6 +44,7 @@ Usage of projects:
$ projects -list

Valid templates include:
- go
- c
- cpp-cmake
- cpp-make
Expand Down
23 changes: 23 additions & 0 deletions internal/templates/golang/golang.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package golang

import (
"path/filepath"

"github.com/moeenn/projects/internal/templates"
)

func NewGolangConfig(args *templates.TemplateArgs) *templates.TemplateConfig {
files := map[string]string{
"go.main_go": filepath.Join(args.RootPath, "main.go"),
"go.go_mod": filepath.Join(args.RootPath, "go.mod"),
}

return &templates.TemplateConfig{
Directories: []string{},
Files: files,
Gitignore: []string{
args.ProjectName,
".DS_Store",
},
}
}
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/moeenn/projects/internal/templates/c"
"github.com/moeenn/projects/internal/templates/cppCmake"
"github.com/moeenn/projects/internal/templates/cppMake"
"github.com/moeenn/projects/internal/templates/golang"
"github.com/moeenn/projects/internal/templates/javaGradle"
"github.com/moeenn/projects/internal/templates/js"
"github.com/moeenn/projects/internal/templates/python"
Expand All @@ -23,8 +24,8 @@ import (
var stubFS embed.FS

var (
TEMPLATE_NAMES = [7]string{
"c", "cpp-cmake", "cpp-make", "javascript (or 'js')", "typescript (or 'ts')", "java-gradle", "python (or 'py')",
TEMPLATE_NAMES = [8]string{
"go", "c", "cpp-cmake", "cpp-make", "javascript (or 'js')", "typescript (or 'ts')", "java-gradle", "python (or 'py')",
}
)

Expand Down Expand Up @@ -65,6 +66,10 @@ func run() error {
config = cppCmake.NewCPPCmakeConfig(templateArgs)
err = templateArgs.Initialize("C++ (Cmake)", config)

case "go":
config = golang.NewGolangConfig(templateArgs)
err = templateArgs.Initialize("Golang", config)

case "js", "javascript":
config = js.NewJSConfig(templateArgs)
err = templateArgs.Initialize("Javascript (vanilla)", config)
Expand Down
5 changes: 5 additions & 0 deletions stubs/golang/go.go_mod.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ define "go.go_mod" }}
module {{ .ProjectName }}

go 1.22.0
{{ end }}
11 changes: 11 additions & 0 deletions stubs/golang/go.main_go.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ define "go.main_go" }}
package main

import (
"fmt"
)

func main() {
fmt.Println("Hello world")
}
{{ end }}

0 comments on commit 5f47692

Please sign in to comment.