生成转义字符

huangapple go评论71阅读模式
英文:

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

huangapple
  • 本文由 发表于 2015年2月17日 17:01:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/28558110.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定