Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for subcommands #3

Closed
ikskuh opened this issue Mar 5, 2020 · 2 comments
Closed

Implement support for subcommands #3

ikskuh opened this issue Mar 5, 2020 · 2 comments
Labels
feature New feature or request

Comments

@ikskuh
Copy link
Owner

ikskuh commented Mar 5, 2020

Using a tagged union instead of a struct for implementing sub commands:

const options = try argsParser.parse(union(enum) {
    fibonacci: struct {
        limit: usize,
    },
    primes: struct {
        limit: usize,
        algorithm: enum { naive, sieve } = .naive,
    },
}, &args, argsAllocator);

This would allow cmd fibonacci --limit and cmd primes --algorithm sieve

@ikskuh ikskuh added the feature New feature or request label Mar 5, 2020
@daurnimator
Copy link

daurnimator commented Mar 5, 2020

What about something like:

const GitArgs = struct {
  options: struct {
      C: zig_args.FilePath,
  },
  sub_commands: union {
    show: struct {
      options: struct {
        bar: bool = false,
      },
      arguments: struct {
        commit: []u8,
      },
    },
  };
};

The subcommands are just nested versions of that top-level struct. Each command would have fields options, subcommands and possibly other fields to set properties for that level.

@ikskuh
Copy link
Owner Author

ikskuh commented Aug 27, 2021

Resolved in edaeb0f

@ikskuh ikskuh closed this as completed Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants