MichalGniadek/klask

File chooser: creating a new file

alexjago opened this issue · 4 comments

Is there a way to specify a file to be created and saved? Obviously clap::ValueHint::FilePath works great for existing files...

Well, you can just write the path manually in the box, but there's no easier way to do it at the moment. But I'm not sure what the best way would be to specify this.

There could be just an additional button on every file path field:
image
But that seems a bit confusing for a user.

I can't think of any way to specify this through clap. Maybe a settings option that's a Vec<String> where you can specify singular fields which save files and not read them?

Yeah I can't think of any way to specify it through clap, and I've just had a look. From clap's perspective there's no real difference between an input and output path. Short of asking/forking clap to add a ValueHint::NewFile. I suppose you could treat ::Other as a non-standard way of asking for a new file or something, but that's a bit of a hack.

It's definitely possible with native_dialog_rs to choose a file, so at least that shouldn't be an issue.

So, probably the best course of action would be to add a setting that allows you to specify field purpose. I won't be able to work on this for a few days, but I will try to implement it later.

Sorry for the wait. I've thought about it more, and there are two ways (both kind of hacky) to specify it in clap:

  • Setting an alias of a field to some value would make it an "input file" field. There's a small chance someone could misspell a field when using the app as CLI and type it by mistake, but it seems unlikely.
  • Setting a value name to some value would make an "input file" field. This would change the help message displayed by clap.