clog-tool / clog-cli

Generate beautiful changelogs from your Git commit history
MIT License
858 stars 43 forks source link

chore: clog should write to stdout #58

Closed 0x-r4bbit closed 9 years ago

0x-r4bbit commented 9 years ago

Currently, clog creates a markdown file by default. As discussed in https://github.com/thoughtram/clog/issues/57, I think it'd make sense if writers could be swapped out.

This raises my next question: Unix commands usually write to stdout by default. If we implement a writer abstraction, so we can plug more into clog, we shouldn't prefer one over the other. Which brings me to the point, that it might be better if clog writes to stdout by default.

Of course, this adds the complexity that you always have to provide a writer option in case you don't want to write to stdout, but this is how most/all UNIX commands work.

Thoughts on this?

kbknapp commented 9 years ago

I'm actually a big fan of this as it follows the unix standard, and upon seeing everything output to the screen, most users will simply

$ clog [options] > changelog.md

What's TBD though is should clog automatically detect previous changelogs? Only if specified in a .clog.toml? Speaking of the .clog.toml that also makes even easier, as you can already specify a file. So if this option is present in the .clog.toml use it, if not, print to stdout.

0x-r4bbit commented 9 years ago

What's TBD though is should clog automatically detect previous changelogs?

Is that needed when clogs simply always prepends?

Speaking of the .clog.toml that also makes even easier, as you can already specify a file. So if this option is present in the .clog.toml use it, if not, print to stdout.

Right, I think .clog.toml is the first place to check. Then provided options. Then defaults.

vyp commented 9 years ago

Is that needed when clogs simply always prepends?

I agree, if the path given (via > changelog.md, or in .clog.toml) points to an already existing file, then it's going to prepend anyway. Otherwise, it's going to create a file. I don't think clog needs to automatically detect changelogs if the default output will be to stdout.

kbknapp commented 9 years ago

I agree. I'd propose the following:

  1. If the user does a clog -o changelog.md and that file exists, prepend and output to the file
  2. If the user does a clog -o changelog.md and the file doesn't exist, create it and output to a file
  3. If the user has the output file set in the .clog.toml check for existance, prepend if needed unless there is a -o which overrides the .clog.toml
  4. If there is no output file specified in the .clog.toml and no -o option, output to stdout

This is actually how clog already functions, minus number 4 which is an easy addition. But should be talked about with #55

Unfortunately, we can't check if clog > mychangelog.md exists because the > mychangelog.md is interpreted by the shell, not clog.

vyp commented 9 years ago

Unfortunately, we can't check if clog > mychangelog.md exists because the > mychangelog.md is interpreted by the shell, not clog.

Yes sorry, my bad. Obviously if the user uses > then they know they are taking the entire output of clog and overwriting whatever might already exist in mychangelog.md. But yes, :+1: to what you propose.

0x-r4bbit commented 9 years ago

@kbknapp

Unfortunately, we can't check if clog > mychangelog.md exists because the > mychangelog.md is interpreted by the shell, not clog.

How do other UNIX command handle that case? git log > logs also creates a file logs if it doesn't exist. ... Ah but it doesn't prepend if it exists...

0x-r4bbit commented 9 years ago

Maybe we should just assume that the user knows how to use > and >> operators?

kbknapp commented 9 years ago

Maybe we should just assume that the user knows how to use > and >> operators?

That's what I'd recommend :+1: (and hope they don't try &> :P )

0x-r4bbit commented 9 years ago

@kbknapp this can easily be part of the developer guide documentation.

vyp commented 9 years ago

Maybe we should just assume that the user knows how to use > and >> operators?

Well yes, see my previous comment. As @kbknapp says, you can't do anything otherwise because > is a shell construct.

If you want to prepend, best use something like:

$ clog > mychangelog.md | cat - mychangelog.md > /tmp/temp && mv /tmp/temp mychangelog.md

Of course, you should just use -o for clog, but for other things you can use that provided you don't have anything important in /tmp/temp.

0x-r4bbit commented 9 years ago

We also shouldn't forget that this would be a breaking change and bumps the version to 1.0.0. I think this is a great opportunity to land this together with the new website, which makes the announcement even nicer :)