最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rust - CLI parsing for tuple of data-bearing enums? - Stack Overflow

programmeradmin2浏览0评论

I have a cli tool that operates effectively on InputArgs, where

struct InputArgs(EnumA, EnumB);
enum EnumA { X, Y { foo: usize } };
struct WArgs { bar: usize };
enum EnumB { W(WArgs), Z };

I.e., there are multiple data-bearing enums, each variant of which needs different args/flags supplied.

What's a convenient/natural/standard way to represent this in cli flags? In particular, I've tried using rust's Clap library, but run into two issues

  • ValueEnum doesn't work with data-bearing enum variants
  • Subcommand does work with data-bearing enum variants (I think), but it doesn't work with multiple of them afaik - in my use case, neither enum is really a "subcommand", but just a nested component.

I guess I'd like to be able to call my program as ./myprogram -y --foo 3 -w --bar 4 or something similar.

发布评论

评论列表(0)

  1. 暂无评论