Skip to content

Add color option to CLI #1355

Closed
Closed

Description

@max-sixty

Currently the CLI can't take options such as --color / --no-color. Ideally we'd be able pass these, and they would flow through with an Options struct to the compiler.

A future version could check whether we're in a TTY and default to --no-color if so (it's also possible that clap offers something like this?).

Labeling as Good first issue (which also make good nth issues). As ever, lots of folks will be happy to answer questions!

Activity

  1. added
    good first issue
    on Dec 28, 2022
  2. Shuozeli commented on Dec 29, 2022

    @Shuozeli
    Contributor

    Hi Max,

    I'd like to work on this. My thought of the steps for adding the option are:

    1. Add one enable_color boolean field in the Option struct under the sql/mod.rs.

    2. Add the cli argument enable_color, color, or no-color to the compile command.

    3. Pass the cli argument as an Option field to the compile function

    Please correct me if my understanding is wrong.

  3. max-sixty commented on Dec 29, 2022

    @max-sixty
    MemberAuthor

    That would be great @Shuozeli !

    I think that sounds very reasonable.

    I would pass a full Options struct to the compile function (I think that's what you were suggesting). And yes re the --color / --no-color flags.

    There's a "smaller" version where we strip out the color at the CLI level, I think that would be easier but less good (but OK!)

    @aljazerzen lmk if you have any thoughts!

  4. aljazerzen commented on Dec 30, 2022

    @aljazerzen
    Member

    Hmm, sql does not do any highlighting ATM, so it doesn't need color option (at least for now). But the cli argument would be use to control this param in error formatting. This function is called

    The best way to do this would be:

    • add a new Options struct to lib.rs:
      struct Options {
          sql: sql::Options,
          color: bool
      }
    • change compile(prql: &str, options: Option<sql::Options>)
      to this compile(prql: &str, options: Option<Options>)
    • add a impl Default for Options and impl From<sql::Options> for Options for convenience
    • make sure that all crates compile and pass cargo test
  5. max-sixty commented on Dec 30, 2022

    @max-sixty
    MemberAuthor

    OK, so we'd have a nested Options struct. That seems very reasonable too.

    @Shuozeli does that make sense to you?

  6. Shuozeli commented on Jan 3, 2023

    @Shuozeli
    Contributor

    Yes, thank you for the clarification. I will be working on this one.

  7. vanillajonathan commented on Feb 11, 2023

    @vanillajonathan
    Collaborator

    @Shuozeli Any progress on this?

  8. added a commit that references this issue on Mar 21, 2023
    4849040
  9. added a commit that references this issue on Mar 21, 2023
    1e87cb7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerfriendlinessgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions