Repository navigation
Allow command-line arguments for "ddev config", fixes #476 - #495
Conversation
0dbf74d to
9617e2a
Compare
|
This showstoppper issue is ready for review. Note that a couple of refactors were done because they were there and I had to find my way around them. They're bulleted in the OP and are mostly separate commits. |
|
Just trying to figure out why some GitHub issues provide a more obvious link to the PR. Test: #476 |
Reference
Preparation
Testing
Discussion & Recommendations
Summarizing requested changes, I would like to see:
|
rickmanelius
left a comment
There was a problem hiding this comment.
Hi @rfay. This is close, but there are a few changes I think we need to make this more robust. Happy to jump on a call to discuss #495 (comment).
|
After a chat w/@rfay, updated summary:
|
| if err != nil { | ||
| util.Failed("There was a problem configuring your application: %v\n", err) | ||
| } | ||
| if siteName == "" && docrootRelPath == "" && pantheonEnvironment == "" { |
There was a problem hiding this comment.
I have mixed feelings about this approach. I'd really like to see a way for providers to each have their own top-level command and register the flags they need. It doesn't feel like this method scales at all beyond our current single provider. it also consolidates a lot of untested logic into our cobra commands, which is a method we've mostly been moving away from.
On the other hand, I realize this is a blocking issue that we're trying to move on relatively quickly. I also realize we only have a single provider right now, so over-engineering for the future has its own risk. Especially when we have no immediate plans to work on additional providers.
There was a problem hiding this comment.
I think you've nailed it. You're definitely right that this doesn't scale very well, but that there's no reason to deal with the architecture until the next provider.
tannerjfco
left a comment
There was a problem hiding this comment.
Some error message suggestions
| appType, err := ddevapp.DetermineAppType(c.Docroot) | ||
| if err != nil { | ||
| fullPath, _ := filepath.Abs(c.Docroot) | ||
| util.Failed("Failed to determine app Type (drupal7/drupal8/wordpress), your docroot may be incorrect - looking in directory %v (full path: %v), err: %v", c.Docroot, fullPath, err) |
There was a problem hiding this comment.
- this could end up being a long message, we might want to consider breaking it to another line.
- i feel like we should avoid displaying "err" to end users. this is already an error message, it seems weird to call out an error inside it. "err" has meaning to go devs, and the implication of "error" is probably enough for most others, but I could see it coming off as a weird message.
- suggestion: "your docroot %v[docroot] may be incorrect - looking in directory %v[abspath]: %v[err]"
There was a problem hiding this comment.
On err: Probably if we're going to get a style guide together for error messages we should get one together, and I fully support that.
I'm always on the debugger's side of this one; in this particular case the user has used a flag that we don't document or suggest. Implementing your suggestion though, which displays the err to end-users anyway :) Since mostly we're the ones that are going to hear about it we need to get this info (especially the err).
| // But pantheon *does* validate "Name" | ||
| err = prov.ValidateField("Name", c.Name) | ||
| if err != nil { | ||
| util.Failed("Failed to validate sitename %v with ddev prov %v err: %v", c.Name, provider, err) |
There was a problem hiding this comment.
Suggestion: "Failed to validate sitename %v[sitename] with %v[provider] provider: %v[err]"
| if _, err := os.Stat(c.ConfigPath); !os.IsNotExist(err) { | ||
| err = c.Read() | ||
| if err != nil { | ||
| return c, fmt.Errorf("config.yaml exists but cannot be successfully read, %v, err=%v", c.ConfigPath, err) |
There was a problem hiding this comment.
Suggestion: "%v[configPath] exists but cannot be read: %v[err]"
|
rickmanelius
left a comment
There was a problem hiding this comment.
Thanks for adding apptype.
| if _, err := os.Stat(c.ConfigPath); !os.IsNotExist(err) { | ||
| err = c.Read() | ||
| if err != nil { | ||
| return c, fmt.Errorf("%v[configPath] exists but cannot be read: %v[err]", c.ConfigPath, err) |
There was a problem hiding this comment.
one of my poorly-formatted suggestions missed the roll-back. sorry for the confusion here.
There was a problem hiding this comment.
Thanks for the sharp eye, fixed.
|
This could probably use some additional validation. Passing in a partial arguments list works as intended but results in some odd messaging. Example: At the very least it would be nice to ensure sitename and environment are both used. |
| fullPath, _ := filepath.Abs(c.Docroot) | ||
| util.Failed("Failed to determine app type (drupal7/drupal8/wordpress).\nYour docroot %v may be incorrect - looking in directory %v, error=%v", c.Docroot, fullPath, err) | ||
| } | ||
| } |
There was a problem hiding this comment.
We probably still want to validate appType against the docroot provided and give a warning if there is a mismatch.
Here's an example of what happened when I used "wordpress" as the apptype for a d7 site:
testing/drupal-kickstart ‹minikube› git:(master) » ddev config pantheon --pantheon-environment=dev --docroot=docroot --apptype=wordpress --sitename=d7kickstart
Found a drupal7 codebase at /Users/beeradb/Projects/testing/drupal-kickstart/docroot
Configuration complete. You may now run `ddev start` or `ddev pull`
Initial configuration file written successfully. See the configuration file for additional configuration options.
It could probably be a more generic validation of the docroot too.
There was a problem hiding this comment.
This looks correct to me. If you specify an appType, it's explicitly overriding the auto-detect. What should it do instead of that?
What kind of generic validation of the docroot would you recommend?
Essentially the command-line is overrides "I know what I'm doing, shut up now". If that's not what we want, something else can happen, but it looks to me like that's what you have here.
There was a problem hiding this comment.
An ideal solution would probably be to accept their value but warn them about a mismatch. i.e. some yellow warning text (or similar) that says something like:
"You specified WordPress as the site type, but this appears to be a Drupal site".
Even people that know what they are doing make mistakes! :)
There was a problem hiding this comment.
What kind of generic validation of the docroot would you recommend?
Again, probably fine to accept the value, but a warning if the directory doesn't exist might be nice. Just in case someone makes a mistake.
|
This seems to break regular ddev config behavior. Example: For a new config: For an existing config: |
beeradb
left a comment
There was a problem hiding this comment.
I was able to find a few bugs which prevent this from being approved at this time.
The seriousness of them may indicate we need to find a way to get test coverage on this. We really don't want to break ddev config functionality.
beeradb
left a comment
There was a problem hiding this comment.
Clicked the wrong button when I approved. Sorry!
| if provider != "pantheon" && pantheonEnvironment != "" { | ||
| util.Failed("--pantheon-environment can only be used with pantheon provider, for example ddev config pantheon --pantheon-environment=dev --docroot=docroot") | ||
| } | ||
| if pantheonEnvironment != "" && pantheonEnvironment != "dev" && pantheonEnvironment != "test" && pantheonEnvironment != "prod" { |
There was a problem hiding this comment.
Small nit: in multidev environments a different value is completely valid. The pantheon plugin will validate this and the sitename if you use provider.Validate() I believe.
a226d2c to
b9a43b7
Compare
|
Thanks for the great bug catch and other coaching, @beeradb - The bug was quite simple, but the fixes to validation are adding more spaghetti than I'd like. But it's real, and it's much more validated. Docroot validation is "does it exist". Sitename and environment are actually validated via pantheon. apptype is forced to d7/d8/wordpress. |
|
Reset the reviewers. |
There was a problem hiding this comment.
This looks much better as a whole. I was able to find a few small issues which I feel are most likely easy fixes, but I'll leave it to you and @rickmanelius to decide if they should be done now or not. Overall, despite the change request, I think most of these issues are pretty minor and I'm fairly comfortable with where this is.
Warning for apptype mismatch
In the following terminal output, I set an apptype of drupal7 against a wordpress code base. We made a lot of good improvements this iteration, but one I'd still love to see is a warning when the user has a mismatch between specified app type and detected app type. I'm OK with accepting the input and moving on, I'd just love to see a message in yellow warning text that says something like:
"You specified an application type of drupal7 but it appears your site is a WordPress site."
I realize we do print the detected app type, but we do so in blue, the color we typically associate with success in the CLI. It makes it blend in with other output and not be very noticeable.
ddev/wordpress ‹minikube› git:(master) ✗ » ddev config pantheon --pantheon-environment=dev --apptype=drupal7 --sitename=d7kickstart
Found a wordpress codebase at /Users/beeradb/Projects/ddev/wordpress
Configuration complete. You may now run 'ddev start' or 'ddev pull'
Site name is reset on a second config
This PR resets the site name on a second config. To reproduce:
- use
ddev configon a site. Give it a unique name. - run
ddev configagain. Notice the name resets to the directory name, rather than using the previously specified site name.
I verified this does not happen on master.
Here's some console output showing the issue:
ddev/wordpress ‹minikube› git:(master) ✗ » ddev config pantheon --pantheon-environment=dev --apptype=drupal7 --sitename=d7kickstart
Found a wordpress codebase at /Users/beeradb/Projects/ddev/wordpress
Configuration complete. You may now run 'ddev start' or 'ddev pull'
testing/d7kickstart2 ‹minikube› git:(master) » ddev config
You are re-configuring /Users/beeradb/Projects/testing/d7kickstart2. The existing configuration will be replaced.
Project name (d7kickstart2):
The docroot is the directory from which your site is served. This is a relative path from your application root (/Users/beeradb/Projects/testing/d7kickstart2)
You may leave this value blank if your site files are in the application root
Docroot Location: ^X^C
testing/d7kickstart2 ‹minikube› git:(master) » cat .ddev/config.yaml
APIVersion: "1"
name: d7kickstart
Config messaging
In a typical ddev config we inform the user about whether they are creating a new config or editing an existing one. That output looks like this:
You are re-configuring /Users/beeradb/Projects/testing/d7kickstart2. The existing configuration will be replaced.
or
Creating a new ddev project config in the current directory (/Users/beeradb/Projects/testing)
Once completed, your configuration will be written to /Users/beeradb/Projects/testing/.ddev/config.yaml
This messaging is not present when using ddev config pantheon with CLI arguments.
rickmanelius
left a comment
There was a problem hiding this comment.
Updated review on 2017-10-10
Reference
Preparation
git checkout rfay/20171002_ddev_config_flagsmake clean && make darwinddev versionoutputsv0.9.2-17-g9aa62985, which matches here 9aa6298.- Clean out sites
ddev rm --remove-dataandrm -rf .ddev
Testing
- Help/instructions
ddev config --helpdisplays:
--apptype string Provide the app type (like wordpress or drupal7 or drupal8). This is normally autodetected and this flag is not necessary
--docroot string Provide the relative docroot of the site, like 'docroot' or 'htdocs' or 'web', defaults to empty, the current directory
-h, --help help for config
--pantheon-environment string Choose the environment for a Pantheon site (dev/test/prod) (Pantheon-only)
--sitename string Provide the sitename of site to configure (normally the same as the directory name)
- Not sure how easy it is to create a stronger break between a provider specific flag. Perhaps a section head "##Flags that are provider specific"?
- Basic Site
- Test with just sitename.
ddev config --sitename=junker99w/docroot https://github.com/drud/wordpress.- This fails for repos with a docroot because the app type can't be detected because the docroot is incorrect.
ddev config --sitename=junker99w/o docroot https://github.com/drud/wordpress and cd htdocs.- This succeeds.
- Test with just a docroot
ddev config --docroot=htdocs- This succeeds with a proper .ddev/config.yml file because the app name is assumed and app detection works.
- Note this will probably still fail if a duplicate app type exists.
- Test with non-Drupal/WordPress app type
ddev config --sitename=junker99- Fails becuse an app type isn't present
- Test with just sitename.
- Pantheon Site
-
Test with sitename only with docroot as parent folder.
ddev config pantheon --sitename=rickmaneliusworks
-
Test with sitename only with docroot one level in.
- This fails because it's missing an app type.
- This succeeds if the docroot is specified, which results in a successful app type detection.
-
Similar issues occur when docroot or type can't be detected.
-
Discussion & Recommendations
- Previously, I surfaced a potential use case when the app-type wasn't Drupal7, Drupal8, or WordPress. Since we already require one of these 3, the concept of supporting a different CMS isn't needed at this point until that functionality is more generically available. See #500 (comment).
- After reviewing our current docs, we don't highlight flags so it's not necessary to update.
- Previously, I was concerned that ddev-ui might not function if we weren't running tests that would catch changes. However, that responsibility should be on ddev-ui tests and will require us to be thoughtful on how we ensure appropriate versions of the CLI and UI are working together.
Summarizing requested changes:
- One nitpick on the error messages: "Failed to determine app type (drupal7/drupal8/wordpress).
Your docroot may be incorrect - looking in directory /Users/rmanelius/git/parent/wordpress, error=DetermineAppType() couldn't determine app's type." Given that this error would only occur when attempting to pass in flags versus an interactive approach, it might be useful to prompt the user with "Your docroot may be incorrect. Looking in directory... Try setting --docroot." This is not critical for approval.
|
Good catches, @beeradb. Summarizing:
All 3 are valid/valuable. I believe the first two could prevent user errors whereas the 3rd would be a nice to have. |
…il.Success(), different stdout
|
You're a rockstar catching those issues @beeradb . I've addressed them each in separate commits. Essentially this add-on code for config stinks pretty badly, should have been developed in tandem with the related PromptForConfig() logic instead of being tacked in later. But that's where we're at. It's hard to justify a significant rework for obscure stuff like this, also hard to justify so much spaghetti code for a simple feature. Hopefully bugs that remain will affect only users of the flags, who hopefully will be only ddev-ui, which will use them predictably. There is a test issue that can be addressed. In 94fe802 I removed 2 (identical) lines of test code that looked for explicit "Creating a new ddev project", which is currently output by util.Success() and via the color output gets out somehow to a different stdout instance. I can either
|
|
@beeradb I think my review of a +1 holds true as long as this addresses the items summarized here #495 (comment). Any chance you'd be able to test/confirm today? |
|
IMO this can go in after we cut a v0.9.3, and that will relieve any worries about unanticipated behavior, and it can also provide @andrew-c-tran with what he needs. |
|
|
||
| // c.Name gets set to basename if not provided, or set to sitneName if provided | ||
| if c.Name != "" && siteName == "" { // If we already have a c.Name and no siteName, leave c.Name alone | ||
| // Sorry this is empty but it make the logic clearer. |
There was a problem hiding this comment.
nit: "but it makes the logic clearer"
There was a problem hiding this comment.
I can handle nits like that!
beeradb
left a comment
There was a problem hiding this comment.
I'm happy with this as-is. The design (or lack thereof) is definitely straining under our slow feature growth here. There are a lot of code smells going on, but they aren't the fault of @rfay in this PR. We definitely need some refactors when we have the time and energy to put into them.
I found a few small issues which should be easy fixes. Mostly just minor messaging updates.
ddev config helpsays "unknown provider type: help" but continues configuration prompts (present in master, not introduced in this PR)ddev config --apptype testsays "apptype must be drupal7 or drupal8 or wordpress" instead of "apptype must be drupal7, drupal8, or wordpress"ddev config pantheon --apptype drupal7 --sitename d7kickstartdefaults to the "dev" environment. This is great, but we should probably inform the user.
Thanks for all your work on this and for putting up with all my feedback 🥇
* Fix failed override of provider introduced in #495 * Fix broken count provided in site count when aborting tests * Improve complex if/else to decide on provider override * Add TestPantheonPull to do an actual app.Import() * Rename App.Config() to App.CreateSettingsFile() * Refactor EnsureDdevNetwork, make sure we have ddev_default at start
The Problem/Issue/Bug:
OP #476: We need to handle config without user prompting, so we'll add new flags to
ddev config.How this PR Solves The Problem:
Manual Testing Instructions:
Start with no site .ddev file.
ddev config,ddev config pantheonddev config --sitename=junker99,ddev config --sitename=junker99 --docroot=docrootddev config pantheon --pantheon-environment=dev --sitename=rfay-drupal8and then try addev pullAutomated Testing Overview:
I didn't add any new automated testing.
Related Issue Link(s):
OP #476
Release/Deployment notes: