foobar如果我的Golang包名称是以下之一,是否可以使用名称构建(安装,获取等)可执行文件:
github.com/username/go-foobargithub.com/username/foobar-tools并main.go在包根?
我正在使用 Cobra 开发一些 CLI 实用程序。对于我,RootCmd我设置了一些持久标志(即也会影响所有命令的标志)。但是有些命令不使用这些标志,所以我想为这些特定命令隐藏它们,所以这些标志不会用myutil help mycmd或显示myutil mycmd --help。
下面的代码片段完成了这项工作,但对我来说它有点难看而且很难维护:
func init() {
RootCmd.PersistentFlags().StringVar(&someVar, "some-flag", "", "Nothing to see here, move along.")
origHelpFunc := TidalCmd.HelpFunc()
RootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
if cmd.Name() == "no-flags-cmd" || (cmd.Parent() != nil && cmd.Parent().Name() == "no-flags-cmd") {
cmd.Flags().MarkHidden("some-flag")
}
origHelpFunc(cmd, args)
})
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来隐藏某些命令的一些全局持久标志?
我正在对各种类型的不同计算引擎实例运行一些测试,我想获取测试脚本当前运行的实例的机器类型以区分结果。
这可以通过gcloudAPI 调用实现吗?
根据Apache Beam 2.0.0 SDK 文档 GroupIntoBatches仅适用于KV集合。
我的数据集只包含值,不需要引入键。然而,为了使用GroupIntoBatches我必须用一个空字符串作为键来实现“假”键:
static class FakeKVFn extends DoFn<String, KV<String, String>> {
@ProcessElement
public void processElement(ProcessContext c) {
c.output(KV.of("", c.element()));
}
}
Run Code Online (Sandbox Code Playgroud)
所以整体管道如下所示:
public static void main(String[] args) {
PipelineOptions options = PipelineOptionsFactory.create();
Pipeline p = Pipeline.create(options);
long batchSize = 100L;
p.apply("ReadLines", TextIO.read().from("./input.txt"))
.apply("FakeKV", ParDo.of(new FakeKVFn()))
.apply(GroupIntoBatches.<String, String>ofSize(batchSize))
.setCoder(KvCoder.of(StringUtf8Coder.of(), IterableCoder.of(StringUtf8Coder.of())))
.apply(ParDo.of(new DoFn<KV<String, Iterable<String>>, String>() {
@ProcessElement
public void processElement(ProcessContext c) {
c.output(callWebService(c.element().getValue()));
}
}))
.apply("WriteResults", TextIO.write().to("./output/"));
p.run().waitUntilFinish();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在不引入“假”密钥的情况下分组?