dongtie0929 2018-06-25 15:32
浏览 92
已采纳

生成后的模板标识

I'm generating a makefile using GO text/template The template is generated as expected (with the right content ) but the problem is that it’s not indented with tabs and I got errors while running make command after generation.

This is the output of the template:

all: app app_2

DIR = $(PWD)
.PHONY: app
app:
@echo "run module 1"

.PHONY: app_2
app_2:
@echo "run module 2”

When I run make I got error "makefile:7: *** missing separator. Stop.” (This is the line with the first echo”)

If I change the ideation to tab (after the file was generated) with Goland or vsCode, I was able to run the file successfully and see the expected output..., any idea how to make it work with go text/template ?

This is the template

all: {{- range .Load.Proc}} {{.Name}}{{end}}


{{- range .Load.Proc}}
.PHONY: {{.Name}}
{{.Name}}:
    @echo {{.Text}}
{{end}}

This is the makefile issue: makefile:4: *** missing separator. Stop but for me it's a problem since I want to generate the file without the need to manually change the indentation.

  • 写回答

1条回答 默认 最新

  • dpiuqwwyu187975836 2018-06-25 16:18
    关注

    Use tab characters in the template to produce tabs in the output. To fix the template in the question, replace the spaces before @echo with a tab character.

    https://play.golang.org/p/c7v6eNsI2Fy

    If you cannot put tabs in the template for some reason, then use {{"\t"}} to produce a tab in the output:

    {{"\t"}}echo {{.Text}}
    

    https://play.golang.org/p/3B-oIW-aCb4

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料