rodydavis / flutter_scripts

MIT License
20 stars 5 forks source link

Piped command fails #4

Open macasas opened 1 year ago

macasas commented 1 year ago

I tried adding a script to my project

scripts:
  generate_diagram: lakos . | dot -T png -Gdpi=200 -o dia_1.png

The command works fine when entered directly to command line. But fails thinking args into dot are still args for lakos, despite using the pipe. Is this not possible?

Running: generate_diagram -> lakos . | dot -T png -Gdpi=200 -o dia_1.png (1/1)
FormatException: Could not find an option or flag "-T".

Usage: lakos [options] <root-directory>

-f, --format=<FORMAT>        Output format.
                             [dot (default), json]
-o, --output=<FILE>          Save output to a file instead of printing it.
                             (defaults to "STDOUT")
    --[no-]tree              Show directory structure as subgraphs.
                             (defaults to on)
-m, --[no-]metrics           Compute and show global metrics.
                             (defaults to --no-metrics)
    --[no-]node-metrics      Show node metrics. Only works when --metrics is true.
                             (defaults to --no-node-metrics)
-i, --ignore=<GLOB>          Exclude files and directories with a glob pattern.
                             (defaults to "!**")
    --[no-]cycles-allowed    With --no-cycles-allowed lakos runs normally
                             but exits with a non-zero exit code
                             if a dependency cycle is detected.
                             Useful for CI builds.
                             (defaults to --no-cycles-allowed)

Update available! 0.0.1 → 0.0.3
Run dart pub global activate flutter_scripts to update

Also, I have run the update, it says I am active on 0.0.3 but always shows this Update Available at end of error message.

Running in dev on a mac M1, 12.6 Monterey.

rodydavis commented 1 year ago

You could put both commands on separate lines!

name:

macasas commented 1 year ago

Thanks for the suggestion, but the output from the first does not get piped into the second. lakos . |pipes an output to the dot command, but with 2 lines it just runs 2 separate commands, so the 2nd line just hangs waiting for a input.

This is what you mean, right?

scripts:
  generate_diagram: 
    - lakos .
    - dot -Tpng -Gdpi=200 -o dia_1.png
rodydavis commented 1 year ago

Yes! And oh I gotcha. Let me look into this. Under the hood it creates a process command for each line and pipes the output to the console.

I’m going to see if this problem is already solved somewhere else

On Fri, Apr 28, 2023 at 10:00 AM Dave @.***> wrote:

Thanks for the suggestion, but the output from the first does not get piped into the second. lakos . | pipes an output to the dot command, but with 2 lines it just runs 2 separate commands, so the 2nd line just hangs waiting for a input.

This is what you mean, right?

scripts: generate_diagram:

  • lakos .
  • dot -Tpng -Gdpi=200 -o dia_1.png

— Reply to this email directly, view it on GitHub https://github.com/rodydavis/flutter_scripts/issues/4#issuecomment-1527835964, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHOOFXZ4XKYYAN4EFNEKPETXDPZRPANCNFSM6AAAAAAXPBZANQ . You are receiving this because you commented.Message ID: @.***>

-- Rody Davis Jr

macasas commented 1 year ago

As a workaround I have created a Makefile in the root containing

diagram: ## Generate dependency diagram
    @echo "╠ Generate dependency diagram..."
    lakos . | dot -T png -Gdpi=200 -o dia_1.png

.. other commands..

add scripts to pubspec.yml

scripts:
  diagram: make diagram
  .. other scripts here linking to other makefile commands

and together this seems to work well.