ollieatkinson / Guise

A tool to generate the Swift public interface for Frameworks and Libraries
MIT License
53 stars 5 forks source link

Allow output to console rather than to disk #10

Closed Sherlouk closed 6 years ago

Sherlouk commented 6 years ago

There might be cases where a client would like to handle the output themselves and do something different. So we should allow the ability to not provided a save path, and instead just output to console.

paulsamuels commented 6 years ago

Would it make sense to add a whole new flag (if so any naming preferences) or use something like --output-file - where - indicates stdout. I've seen this convention used before plutil is an example of using this for stdout and paste is an example of using - for stdin.

ollieatkinson commented 6 years ago

I think an extra flag incase you want to output to a file and print out the result to the console. How about --output-console?

paulsamuels commented 6 years ago

In not sure how the UI looks to print to stdout and not a file. The use case of outputting to a file and stdout seems like it should be handled with something like tee

ollieatkinson commented 6 years ago

That's the bit I'm struggling with at the moment too. If --output-file - is a paradigm then I can do a PoC

paulsamuels commented 6 years ago

Seems reasonable to start and should be small to change

ollieatkinson commented 6 years ago

It seems that in Commandant, for --output-file - it's expecting to extract a value:

guard index < oldArguments.count, case let .value(value) = oldArguments[index] else {
    return .failure(missingArgumentError("--\(key)"))
}

And therefore we get a Missing argument for --output-file

Output:

(lldb) po arg
▿ --output-file
  - key : "output-file"

(lldb) po oldArguments
▿ 2 elements
  ▿ 0 : --output-file
    - key : "output-file"
  ▿ 1 : -
    ▿ flag : OrderedSet<Character>
      - values : 0 elements

(lldb) po index
1

(lldb) po oldArguments.count
2

(lldb) po oldArguments[index]
▿ -
  ▿ flag : OrderedSet<Character>
    - values : 0 elements

RawArgument does support flags, but the value it's consuming needs to be a boolean

paulsamuels commented 6 years ago

If you can’t do the - thing then maybe just have a Boolean flag that uses stdout and overrides (read ignores) output-file

ollieatkinson commented 6 years ago

I think the best solution here would be to remove the ability for the tool to output to a file, and we can let the user direct stdout to wherever they want.

e.g.

guise generate > $PROJECT_DIR/API.swift