Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb4fe69e

Browse files
committed
feat(cmd): add makefile generator
1 parentc3a5cbc commitb4fe69e

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

‎cmd/makefile.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"github.com/sirupsen/logrus"
8+
"github.com/spf13/cobra"
9+
10+
"github.com/cage1016/ak/generator"
11+
)
12+
13+
// makefileCmd represents the makefile command
14+
varmakefileCmd=&cobra.Command{
15+
Use:"makefile",
16+
Short:"Add Makefile to project",
17+
Aliases: []string{"mf"},
18+
Run:func(cmd*cobra.Command,args []string) {
19+
iferr:=generator.NewMakefileGenerator().Generate();err!=nil {
20+
logrus.Fatal(err)
21+
}
22+
},
23+
}
24+
25+
funcinit() {
26+
addCmd.AddCommand(makefileCmd)
27+
}

‎generator/makefile.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package generator
2+
3+
import (
4+
"github.com/cage1016/ak/fs"
5+
"github.com/cage1016/ak/template"
6+
"github.com/sirupsen/logrus"
7+
"github.com/spf13/viper"
8+
)
9+
10+
typeMakefileGeneratorstruct{}
11+
12+
func (mf*MakefileGenerator)Generate()error {
13+
te:=template.NewEngine()
14+
defaultFs:=fs.Get()
15+
16+
data,err:=te.Execute("makefile",map[string]interface{}{
17+
"GoModPackage":viper.GetString("go_mod_package"),
18+
})
19+
iferr!=nil {
20+
returnerr
21+
}
22+
23+
err=defaultFs.WriteFile("Makefile",data,viper.GetBool("ak_force"))
24+
iferr!=nil {
25+
returnerr
26+
}
27+
logrus.Debugf("wrote Makefile")
28+
29+
returnnil
30+
}
31+
32+
funcNewMakefileGenerator()*MakefileGenerator {
33+
return&MakefileGenerator{}
34+
}

‎template/bindata.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎template/tmpl/makefile.tmpl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
ENABLED_AUTO_UPDATE ?= "false"
2+
LDFLAGS ?= -X {{.GoModPackage}}/cmd.EnabledAutoUpdate=$(ENABLED_AUTO_UPDATE)
3+
4+
HAVE_GO_BINDATA := $(shell command -v go-bindata 2> /dev/null)
5+
generate: ## go generate
6+
ifndef HAVE_GO_BINDATA
7+
@echo "requires 'go-bindata' (go get -u github.com/kevinburke/go-bindata/go-bindata)"
8+
@exit 1 # fail
9+
else
10+
go generate ./...
11+
endif
12+
13+
.PHONY: build
14+
build: generate ## build the binary
15+
ak alfred build -l "$(LDFLAGS)"
16+
17+
.PHONY: info
18+
info: ## show alfred workflow info
19+
ak alfred info
20+
21+
.PHONY: link
22+
link: ## link alfred workflow
23+
ak alfred link
24+
25+
.PHONY: unlink
26+
unlink: ## unlink alfred workflow
27+
ak alfred unlink
28+
29+
.PHONY: pack
30+
pack: ## pack alfred workflow
31+
ak alfred pack
32+
33+
.PHONY: help
34+
help: ## this help
35+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_0-9-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
36+
37+
.DEFAULT_GOAL := help

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp