Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddev help doesn't respect --json-output #5567

Closed
1 task done
GuySartorelli opened this issue Nov 25, 2023 · 7 comments
Closed
1 task done

ddev help doesn't respect --json-output #5567

GuySartorelli opened this issue Nov 25, 2023 · 7 comments

Comments

@GuySartorelli
Copy link
Collaborator

Is there an existing issue for this?

  • I have searched the existing issues

Output of ddev debug test

Expand `ddev debug test` diagnostic information
Running bash [-c /tmp/test_ddev.sh] 
Please try running this in an existing DDEV project directory, preferably the problem project.
It doesn't work in other directories.
Failed running test_ddev.sh: exit status 2
. You can run it manually with `curl -sL -O https://raw.githubusercontent.com/ddev/ddev/master/cmd/ddev/cmd/scripts/test_ddev.sh && bash test_ddev.sh`

Which makes sense - this bug report has nothing to do with projects. I don't have any current ddev projects to run the command in, and I don't think the output is relevant so I'm not gonna bother spinning one up unless I really have to.

Expected Behavior

The help information should respect the global --json-output or -j flag, and output its information in JSON format. This would make the output easy to interpret programmatically.

Actual Behavior

The output is the same as though you hadn't used the --json-output or -j flag. This means it is not easy to interpret programmatically.

Steps To Reproduce

  1. Run ddev help <command> --json-output
  2. Observe that the output is not in JSON format.

Anything else?

I'm writing a wrapper around DDEV that allows me to further customise the DDEV CLI. Part of this requires being able to programmatically interpret the output from the help command so that my wrapper can use that information to know what flags any given DDEV command will accept, among other things. I'm doing that with REGEX at the moment, but theoretically the way the output is displayed could change tomorrow and break it. If I could get the information as a JSON object, the normal text output could change without breaking my code (along with being easier to fetch the relevant information in the first place).

@rfay
Copy link
Member

rfay commented Nov 25, 2023

I'd be interested in hearing what you're up to :)

A contribution here is welcome, but it's not likely to make high priority at this point.

Related:

@GuySartorelli
Copy link
Collaborator Author

I'd be interested in hearing what you're up to :)

My current dev environment is a self-rolled symfony console app with a custom docker container. I want to swap to DDEV but I often need to create multiple new projects a day, with specific requirements, and sometimes do things like pull specific PRs into those projects. Doing that with DDEV as-is would require multiple commands for each project setup.

DDEV doesn't currently have a way to easily add new commands that work before you have your project set up - from what I can see, even "global" commands only work when you're in the directory of an existing project. So I'm wrapping DDEV so I can have a single executable for my custom commands and existing DDEV commands.

A contribution here is welcome

I'll take a look and see what I can see - but I'm not familiar with GO nor with the DDEV codebase so it's not likely I'll be able to put a solution together in the time I have.

@GuySartorelli
Copy link
Collaborator Author

Looks like DDEV is using the default help command provided by cobra, which can be customised - but given I'm not familiar with GO, cobra, nor the DDEV codebase, this is beyond my abilities right now.

If someone can point me to the right place to implement the customisation, and give me any pointers about how to go about doing so, I can look at it a bit more... but for now this is as far as I can go.

@rfay
Copy link
Member

rfay commented Nov 26, 2023

DDEV doesn't currently have a way to easily add new commands that work before you have your project set up

Project level host custom commands do work immediately.

But consider a little shell script wrapper :) I think you're working way too hard.

@GuySartorelli
Copy link
Collaborator Author

GuySartorelli commented Nov 26, 2023

Project level host custom commands do work immediately.

Right... but I need global commands for before a project exists. Not project-level commands.

consider a little shell script wrapper

That would require writing my custom commands as shell scripts, and I'm much more comfortable with PHP. I'm not even sure how to make a shell script wrapper :p so I'll stick with what I know.

Regardless of my usecase though, I think this bug report is valid. We should probably keep any discussion about my use-case somewhere else (maybe open a discussion if you want to talk more about it?) to avoid adding too many comments to this issue that don't directly relate to the bug report.

@rfay
Copy link
Member

rfay commented Nov 26, 2023

I would love to have you experiment with Cobra. You already knew enough to find out how it works, you can probably get all the way with it. Quite a number of DDEV users have become golang contributors, docs are quite good, https://ddev.readthedocs.io/en/latest/developers/building-contributing/

@GuySartorelli
Copy link
Collaborator Author

I've raised #5572

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants