Skip to content

Better API or docs #1

Description

@ai

Let’s think how we make CLI better.

Activity

  1. corysimmons commented on Jan 30, 2016

    @corysimmons
    Contributor

    @hawkrives seemed to have the best idea. @hawkrives care to put your proposed syntax in here?

  2. corysimmons commented on Jan 30, 2016

    @corysimmons
    Contributor

    @ai If we rewrite this from scratch does this need to be a fork? Looks funny.

  3. hawkrives commented on Jan 31, 2016

    @hawkrives

    Oh, uh, I'll go look for my proposal. Was it in the old repo somewhere?

  4. hawkrives commented on Jan 31, 2016

    @hawkrives

    Found it.

    TL;DR: postcss -p autoprefixer input.css > output.css and postcss -p [ autoprefixer -b "browsers" ] input.css > output.css, using subarg.

    For other references, check out Browserify: browserify -t [ babelify --experimental ] -e input.js > output.js

    Browserify gets all the arguments outside of the square brackets, and passes the ones inside to the invoked command.

    The arguments are parsed into something like:

    • Browserify
      • -e input.js
      • -t
        • babelify
          • --experimental

    Substack pulled the subarg parsing into its own package, at subarg.

    An example for PostCSS would probably look something like postcss -p [ autoprefixer -b "browsers" ] input.css > output.css

    Note that if you don't want to pass any args to the plugin, you dont need the brackets: postcss -p autoprefixer input.css > output.css

  5. hawkrives commented on Jan 31, 2016

    @hawkrives

    and/or other proposal:

    postcss [-p plugin]] [some input files] [-o output-file] [--out-dir dir]

    • Any number of plugins, each with its own -p .
    • Each plugin can be either just a name, like autoprefixer, or it can pass options with subarg, like [autoprefixer --no-remove].
    • Any number of input files
      • If you give one input file, and no output, it'll write to stdout
      • If you give -o with one input file, it writes to that file
      • If you give multiple inputs, and no --out-dir, it'll overwrite the input files
      • If you give --out-dir with multiple input files, it'll write the corresponding files to the specified directory

    I took --out-dir from Babel's cli.

  6. corysimmons commented on Jan 31, 2016

    @corysimmons
    Contributor

    @hawkrives Thanks. How would multiple plugin options work?

    For instance, what if I wanted to pass browsers: last 2 versions and remove: false with Autoprefixer?

  7. hawkrives commented on Jan 31, 2016

    @hawkrives

    Probably something like postcss -p [autoprefixer --browsers="last 2 versions" --no-remove] input.css, which would result in the autoprefixer plugin getting {browsers: 'last 2 versions', remove: false} as options.

    (subarg and therefore minimist treat --no-arg and --arg=false the same, returning {arg: false} either way.)

  8. corysimmons commented on Jan 31, 2016

    @corysimmons
    Contributor

    Gotcha. I think I like the plugin name on the outside of the brackets a bit better.

    postcss -p [autoprefixer --browsers="last 2 versions" --no-remove] -p [cssnano --safe --sourcemap] -p postcss-cssnext input.css
    postcss -p autoprefixer [--browsers="last 2 versions" --no-remove] -p cssnano [--safe --sourcemap] -p postcss-cssnext input.css
    

    I'm also not sure I like the arrow.

    postcss input.css > output.css
    postcss input.css -o output.css
    

    Thoughts?

    Sidenote: I've been using Browserify all night to get more familiar with it's syntax. I can't help but to think there are a lot of brackets and curly braces involved.

    "transform": [["babelify", { "presets": ["es2015"] }]] <- this is a real thing I hope postcss-cli can avoid.

  9. corysimmons commented on Jan 31, 2016

    @corysimmons
    Contributor

    Anyone have any special feelings about https://github.com/sindresorhus/meow ? Looks pretty kewl to me. 💯

  10. TrySound commented on Jan 31, 2016

    @TrySound
    Member

    @corysimmons meow does not allow to use file config, only field from package.json. We have https://github.com/davidtheclark/cosmiconfig for such cases.

  11. corysimmons commented on Jan 31, 2016

    @corysimmons
    Contributor

    We can use the two together right?

  12. TrySound commented on Jan 31, 2016

    @TrySound
    Member

    Hm.. yep, right.

  13. corysimmons commented on Jan 31, 2016

    @corysimmons
    Contributor

    💯

  14. vincentorback commented on Jan 31, 2016

    @vincentorback

    Adding value of false to the output option should not write to any file: -o false.
    This would be great if you just want to parse CSS for eg. linting.

  15. vitorgalvao commented on Jan 31, 2016

    @vitorgalvao

    I'm also not sure I like the arrow.

    That’s standard unix redirection, so it makes sense for it to be there, you can’t really take it out.

    Adding value of false to the output option should not write to any file: -o false.

    Why complicate? Just behave like any other *nix tool.

    I’m pretty sure what @hawkrives meant was for it to behave akin to curl. If you don’t specify an output, it’ll just output to STDOUT (i.e. show on the terminal). If you give it > file_name, it’ll write to file_name instead of being shown on the terminal. -o file_name would behave exactly the same as > file_name, but -o needs to be built into the tool, while > will just work by default, since it’s your shell doing the work, there.

  16. 52 remaining items

  17. vitorgalvao commented on Feb 18, 2016

    @vitorgalvao

    I’m in agreement with @sindresorhus, for one simple important reason: clarity. I remember fighting with a tool (perhaps it was postcss-cli, even) some time ago while trying to figure out how to convert the examples in the a plugin pages to actual -- commands (don’t remember the actual issue, perhaps there were nested commands, or something).

    I’m a heavy CLI user and build a lot of (mostly) bash and ruby scripts with flags. Even though -- flags make sense and are familiar, in this case we’re passing options to other tools and at some point it just becomes confusing.

    Take this autoprefixer example. With @sindresorhus’ suggestion, it’d be trivial to convert. No need to transform their options into -- flags, just copy and paste the example as is in the correct place.

    From the two examples, I think I prefer the first, but any of them seems like an improvement over the alternatives.

  18. corysimmons commented on Feb 18, 2016

    @corysimmons
    Contributor

    postcss --plugin-autoprefixer="browsers: 'last 2', remove: false" --plugin-something="foo: 'bar'" I like that.

    @ai Objections?

    Also, is anyone considering stepping up to dev this?

  19. sindresorhus commented on Feb 18, 2016

    @sindresorhus

    And as commented in sindresorhus/meow#30 (comment), you can use levn to parse the value.

  20. rafaelrinaldi commented on Mar 3, 2016

    @rafaelrinaldi

    Thinking about submitting a PR with improved instructions on the use of a configuration JSON (instead of CLI arguments). It was kinda tricky for me at first and some people at work also got confused by it.

    @ai Thoughts?

  21. corysimmons commented on Mar 3, 2016

    @corysimmons
    Contributor

    It'd be nice if we exposed config files to all 3 standard config types as well as CLI args: https://github.com/davidtheclark/cosmiconfig

  22. corysimmons commented on Apr 8, 2016

    @corysimmons
    Contributor

    @ai Can you finalize this so someone can move forward?

  23. RyanZim commented on Sep 9, 2016

    @RyanZim
    Collaborator

    @ai ping?

  24. ai commented on Sep 9, 2016

    @ai
    MemberAuthor

    @RyanZim I don’t use this project, so my thoughts will not be useful :)

  25. ai commented on Sep 9, 2016

    @ai
    MemberAuthor

    But, right now I am thinking about having one common config for any PostCSS runner: https://github.com/michael-ciniawsky/postcss-load-plugins and https://github.com/michael-ciniawsky/postcss-load-config

    I think CLI also should use that common config.

  26. watilde commented on Sep 9, 2016

    @watilde
    Member

    Personally, I agreed on this #1 (comment) and also I'd like to update all the cli option as well at the same time, like a breaking change.

  27. michael-ciniawsky commented on Sep 15, 2016

    @michael-ciniawsky
    Contributor

    👋

    --env|e

    postcss --env|e  production
    
    {
      "name": "css",
      "main": "postcss.config.js",
      "scripts": {
        "css:prod": "NODE_ENV=production postcss -o dest/index.css src/index.css",
        "css:dev": "NODE_ENV=development postcss -o dest/index.css src/index.css",
      },
    }

    --help|h

    postcss --help|h  $plugin
    

    npm home $plugin > npm repo $plugin > README.md (e.g github-man)

    --bundle|b

    postcss -p sugarss -u [postcss-import --option foo --option bar] ...
    
    postcss --bundle|b $name
    

    postcss-config-boilerplate

    |–index.js (postcss.config.js)
    |-package.json
    |-README.md
    

    package.json

    {
      "name": "postcss-config-[name]",
      "main": "index.js",
      "postcss": {
        "parser": "sugarss",
        "plugins": {
          "postcss-import": { option: 'foo', option: 'bar' }
        }
      },
      "dependencies": {
         "postcss-import": "^8.1.2"
      }
    }

    index.js (postcss.config.js)

    const options = require('package.json').postcss
    const plugins = require('package.json').postcss.plugins
    
    module.exports = (ctx) => {
      parser: ctx.parser || options.parser
      plugins: {
         'postcss-import': ctx.import || plugins['postcss-import']
         ...
      }
    }
  28. thomasklein commented on Jan 5, 2017

    @thomasklein

    Hi guys! Any news on using cosmiconfig?

  29. RyanZim commented on Jan 5, 2017

    @RyanZim
    Collaborator

    @thomasklein Right now, we are working on postcss-cli v3. That is a complete rewrite that will use https://github.com/michael-ciniawsky/postcss-load-config, which uses cosmiconfig under the hood. See https://github.com/postcss/postcss-cli/projects/1 for more details and progress updates.

  30. RyanZim commented on Mar 20, 2017

    @RyanZim
    Collaborator

    v3.0.0 is out, so going to say that fixes this issue. https://github.com/postcss/postcss-cli/releases/tag/v3.0.0

    Please open new issues for anything that you think could be improved. Thanks for all the brainstorming here!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions