英文:
Go generate escape characters
问题
我有一个类似这样的go generate指令:
//go:generate myprog -someName thisname -data 'Request: Typ "." callMe, Rsp: MyTyp "." close'
问题是程序只接收到-someName
标志的值("thisname")。我猜测-data
标志被丢弃了,可能是由于某些原因。你有什么想法吗?如果我直接从命令行执行程序,它是可以工作的,所以我猜这是一个go特定的问题。
英文:
I have a go generate directive which looks like this:
//go:generate myprog -someName thisname -data 'Request: Typ "." callMe, Rsp: MyTyp "." close'
The issue is that the program receives only value of -someName
flag ("thisname"). I assume the -data
flag is discarded for some reasons. Any idea why? It's working if I execute the program directly from command line so I guess it's a go specific issue.
答案1
得分: 5
从go generate的设计文档中(https://docs.google.com/document/d/1V03LUfjSADDooDMhe-_K59EgpTEm3V8uvQRuNMAEnjg/edit):
> 当运行生成器时,参数是以空格分隔的标记(或双引号字符串)作为单独的参数传递给生成器。
因此,如果您想传递包含空格的参数,您将需要用双引号引起来。您使用了单引号,在您的shell中可以工作,但在go generate
中不起作用。
英文:
From the design document of go generate https://docs.google.com/document/d/1V03LUfjSADDooDMhe-_K59EgpTEm3V8uvQRuNMAEnjg/edit:
> The arguments are space-separated tokens (or double-quoted strings) passed to the generator as individual arguments when it is run.
So if you want to pass an argument containing space you will have to double quote them. You used single quotes which works in your shell but not with go generate
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论