EmbarkStudios / texture-synthesis

🎨 Example-based texture synthesis written in Rust 🦀

Home Page:http://embark.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Another CLI UI strangeness:

Jake-Shadle opened this issue · comments

Another CLI UI strangeness:

        --out-fmt <out-fmt>                       
            The format to save the generated image as.
            
            NOTE: this will only apply when stdout is specified via `-o -`, otherwise the image format is determined by
            the file extension of the path provided to `-o` [default: png]

Explicit command-line option should override any sort of auto-detection.

Originally posted by @vi in #20 (comment)

... or rename the switch to --stdout-fmt 😛

Otherwise it's probably weird if you specify foo.png as output, yet it ends up being a JPEG with a .png extension because you used --out-fmt jpg (or it gets renamed to foo.jpg, thus disagreeing with the value for the -o switch)

Yah, that's what I was going to do, because it would indeed be very confusing to have the mismatch, which is why it currently operates this way.

This "explicit command line overrides filename extension" rule is mostly for scripting, not for manual invocation.

Filename may be user-specified, texture-synthesis result is just some intermediate output. If filename is out.jpg it may still end up as JPG, but not from texture-synthesis, rather at some later stage.

Current option --out-fmt indeed works as if it were --stdout-fmt:

$ texture-synthesis  --out-fmt png  --out qqq generate q.png 
[00:00:22] ######################################## 100%
 stage   6 ######################################## 100%
error: Unsupported image format image/""

I expect command-line tools to work with filenames like /tmp/tmp.HpdW5bEo1g if format is explicitly specified.

So in the scenario you just described, would you be ok if it worked like

#!/bin/bash

out_file=$(mktemp)
texture-synthesis --stdout-fmt bmp --out - generate imgs/1.jpg > $out_file`
echo "$(file $out_file)"

That way the "normal" case of the user using the file extension to determine the output format still works, and gives an error if it's an unrecognized/unsupported output format, but in a more advanced scripting scenario where you want more control, you have to write to stdout and do whatever redirection or piping you need afterwards.

With --stdout-fmt instead of --out-fmt it is at least not contradictory and not unexpected.

Problems may arise if we would need to ouput multiple images. Typically there's only one stdout.

Sure, but such a change would drastically change the CLI entirely, so should be fine for now.