alecthomas / alecthomas/kong

Switching command based on os.Args[0]

Đang mở
#369 3 bình luận 2 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
3.2k
Fork
188
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
2

Mô tả

It's happened a few times now that I've migrated separate utility programs in as sub-commands of a larger program that uses Kong. In those cases, it would sometimes be neat to continue to provide the old binary name (via a symlink, hard link, or whatever) and have things continue to work.

As a concrete example, there is currently `syncthing` (a program) and `strelaysrv` (a different, supporting program). Migrating `strelaysrv` into `syncthing` so that it can be called as `syncthing relaysrv ...` is easy and clean. It would be nice if we could also say something like

```
struct CLI {
Serve serveCmd `cmd:"" default:""`
// ...
Relaysrv relaysrv.CLI `cmd:"" default-when-argv0-is:"strelaysrv"`
}
```

and then calling the binary as `strelaysrv` would be equivalent to typing `syncthing relaysrv`.

Alternatively, there's perhaps some magic that can be done via variable interpolation to tweak what is the default command before calling `kong.Parse()`?

As it is, I'm setting up an args slice myself based on os.Args, tweaked to simulate that the longer form command was run, and then pass that to a kong parser.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.