Skip to content

Allow command-line arguments for "ddev config", fixes #476 - #495

Merged
rfay merged 22 commits into
ddev:masterfrom
rfay:20171002_ddev_config_flags
Oct 17, 2017
Merged

rfay merged 22 commits into
ddev:masterfrom
rfay:20171002_ddev_config_flags

Conversation

@rfay

@rfay rfay commented Oct 2, 2017 •

Copy link
Copy Markdown
Member

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:

  • Add new flags for configuration --sitename --docroot --pantheon-environment
  • Rename Pantheon's "Environment" to "EnvironmentName", since there was also an "environment" and it was impossible to figure out which was which.
  • Rename Config() to PromptForConfig() to make the code more readable.
  • Refactor Config() so it doesn't return an error when there's no existing config.yaml - instead it only returns an error when the existing has problems.

Manual Testing Instructions:

Start with no site .ddev file.

  • Test existing config paths (ddev config, ddev config pantheon
  • ddev config --sitename=junker99, ddev config --sitename=junker99 --docroot=docroot
  • ddev config pantheon --pantheon-environment=dev --sitename=rfay-drupal8 and then try a ddev pull

Automated Testing Overview:

I didn't add any new automated testing.

Related Issue Link(s):

OP #476

Release/Deployment notes:

@rfay rfay self-assigned this Oct 2, 2017
@rfay
rfay force-pushed the 20171002_ddev_config_flags branch from 0dbf74d to 9617e2a Compare October 2, 2017 18:24
@rfay rfay changed the title Use command-line arguments for configuration, fixes #476 Allow command-line arguments for configuration, fixes #476 Oct 2, 2017
@rfay
rfay requested a review from beeradb October 2, 2017 22:37
@rfay

rfay commented Oct 2, 2017

Copy link
Copy Markdown
Member Author

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.

@rickmanelius

Copy link
Copy Markdown
Contributor

Just trying to figure out why some GitHub issues provide a more obvious link to the PR. Test: #476

@rickmanelius

rickmanelius commented Oct 3, 2017 •

Copy link
Copy Markdown
Contributor

Reference

Preparation

  • git checkout rfay/20171002_ddev_config_flags
  • make clean && make darwin
  • ddev version outputs v0.9.2-6-ge59635d2, which matches here e59635d.
  • Clean out site ddev rm --remove-data and rm -rf .ddev

Testing

  • Help/instructions
    • ddev config --help displays:
    --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   Provide the environment for a Pantheon site (Pantheon-only) (default "dev")
    --sitename string               Provide the sitename of site to configure (normally the same as the directory name)

Discussion & Recommendations

  • I'm tryng to think through a situation where an end-user (through the UI) is adding a non-WP or non-Drupal app. Perhaps we could default the docroot and type values and provide a warning if we cannot find the index.php file? This might also just be the responsibility of the UI to ensure a type and docroot are being passed. However, I could see CLI users liking the ability to generate configs programmatically versus through prompts. Perhaps this could be resolved by prompting a user with additional instructions to set the the docroot flag and/or type flags if a failure occurs?
  • For completeness, it would be helpful to have a type flag as it's part of the main configuration (even if we do auto detection)
  • I note on the PR that no tests are applied. I would say that it would be helpful to verify that a type + docroot + name succeeds only because ddev UI functionality could break if those flags change names.
  • Would it make sense to update our readthedocs?

Summarizing requested changes, I would like to see:

  • The type flag added.
  • A test to ensure that we catch a name change of these flags.
  • An additional statement after the failure to add the appropriate flag (docroot and/or type) if sitename alone isn't sufficient.
  • (Optional) update to readthedocs if we find an appropriate place.

@rickmanelius
rickmanelius self-requested a review October 3, 2017 16:38

@rickmanelius rickmanelius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@rickmanelius

Copy link
Copy Markdown
Contributor

After a chat w/@rfay, updated summary:

  • The type flag added.
  • Tests for flag names will be on ddev UI.
  • Docs will be re-evaluated in the larger meta-issue here Documentation Audit #242

Comment thread cmd/ddev/cmd/config.go Outdated
if err != nil {
util.Failed("There was a problem configuring your application: %v\n", err)
}
if siteName == "" && docrootRelPath == "" && pantheonEnvironment == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 tannerjfco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some error message suggestions

Comment thread cmd/ddev/cmd/config.go Outdated
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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]"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread cmd/ddev/cmd/config.go Outdated
// 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: "Failed to validate sitename %v[sitename] with %v[provider] provider: %v[err]"

Comment thread pkg/ddevapp/config.go Outdated
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: "%v[configPath] exists but cannot be read: %v[err]"

@rfay

rfay commented Oct 3, 2017

Copy link
Copy Markdown
Member Author
  • Added the --apptype flag
  • Thanks for the suggested improved error messages @tannerjfco - did those.

@rickmanelius
rickmanelius self-requested a review October 3, 2017 20:27

@rickmanelius rickmanelius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding apptype.

@rfay rfay changed the title Allow command-line arguments for configuration, fixes #476 Allow command-line arguments for "ddev config", fixes #476 Oct 3, 2017
Comment thread pkg/ddevapp/config.go Outdated
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one of my poorly-formatted suggestions missed the roll-back. sorry for the confusion here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the sharp eye, fixed.

@beeradb

beeradb commented Oct 6, 2017 •

Copy link
Copy Markdown
Contributor

This could probably use some additional validation. Passing in a partial arguments list works as intended but results in some odd messaging. Example:

testing/drupal-kickstart ‹minikube› git:(master) » ddev config pantheon --pantheon-environment=dev --docroot=docroot
Found a drupal7 codebase at /Users/beeradb/Projects/testing/drupal-kickstart/docroot
Failed to validate sitename  with provider pantheon: could not find a pantheon site named

At the very least it would be nice to ensure sitename and environment are both used.

Comment thread cmd/ddev/cmd/config.go
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)
}
}

@beeradb beeradb Oct 6, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@beeradb

beeradb commented Oct 6, 2017 •

Copy link
Copy Markdown
Contributor

This seems to break regular ddev config behavior. Example:

For a new config:

testing/drupal-kickstart ‹minikube› git:(master) ✗ » ddev config
Failed to determine app type (drupal7/drupal8/wordpress).
Your docroot  may be incorrect - looking in directory /Users/beeradb/Projects/testing/drupal-kickstart, error=DetermineAppType() couldn't determine app's type

For an existing config:

testing/wordPress ‹minikube› git:(test) » ddev config
Found a  codebase at /Users/beeradb/Projects/testing/wordPress
Configuration complete. You may now run `ddev start` or `ddev pull`
Initial configuration file written successfully. See the configuration file for additional configuration options.

@beeradb beeradb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 beeradb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clicked the wrong button when I approved. Sorry!

Comment thread cmd/ddev/cmd/config.go Outdated
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" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rfay
rfay force-pushed the 20171002_ddev_config_flags branch from a226d2c to b9a43b7 Compare October 6, 2017 21:45
@rfay

rfay commented Oct 6, 2017

Copy link
Copy Markdown
Member Author

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.

@rickmanelius
rickmanelius self-requested a review October 10, 2017 17:25
@rickmanelius

Copy link
Copy Markdown
Contributor

Reset the reviewers.

@beeradb beeradb left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. use ddev config on a site. Give it a unique name.
  2. run ddev config again. 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 rickmanelius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated review on 2017-10-10

Reference

Preparation

  • git checkout rfay/20171002_ddev_config_flags
  • make clean && make darwin
  • ddev version outputs v0.9.2-17-g9aa62985, which matches here 9aa6298.
  • Clean out sites ddev rm --remove-data and rm -rf .ddev

Testing

  • Help/instructions
    • ddev config --help displays:
      --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
  • Pantheon Site
    • Test with sitename only with docroot as parent folder.

      • ddev config pantheon --sitename=rickmanelius works
    • 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.

@rickmanelius

Copy link
Copy Markdown
Contributor

Good catches, @beeradb. Summarizing:

  • Optimization: We may need a test to catch the regression of sitename resetting.
  • Optimization: Provide warning for app type mismatch (only occurs with flags)
  • Consistency: Ensure config pantheon reports similar messaging when updating config.

All 3 are valid/valuable. I believe the first two could prevent user errors whereas the 3rd would be a nice to have.

@rfay

rfay commented Oct 11, 2017

Copy link
Copy Markdown
Member Author

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

  1. Switch back to fmt.Printf() to output that
  2. Remove the test for that exact phrase (as I did in 94fe802) or
  3. Figure out how to capture the stdout that color package is using (which seems quite extravagant)

@rickmanelius

Copy link
Copy Markdown
Contributor

@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?

@rfay

rfay commented Oct 16, 2017

Copy link
Copy Markdown
Member Author

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.

Comment thread cmd/ddev/cmd/config.go Outdated

// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "but it makes the logic clearer"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can handle nits like that!

@beeradb beeradb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. ddev config help says "unknown provider type: help" but continues configuration prompts (present in master, not introduced in this PR)
  2. ddev config --apptype test says "apptype must be drupal7 or drupal8 or wordpress" instead of "apptype must be drupal7, drupal8, or wordpress"
  3. ddev config pantheon --apptype drupal7 --sitename d7kickstart defaults 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 🥇

@rfay
rfay merged commit 4ca6d38 into ddev:master Oct 17, 2017
@rfay
rfay deleted the 20171002_ddev_config_flags branch October 17, 2017 20:46
rfay added a commit to rfay/ddev that referenced this pull request Oct 24, 2017
rfay added a commit to rfay/ddev that referenced this pull request Oct 31, 2017
rfay added a commit to rfay/ddev that referenced this pull request Nov 7, 2017
rfay added a commit to rfay/ddev that referenced this pull request Nov 8, 2017
rfay added a commit to rfay/ddev that referenced this pull request Nov 8, 2017
rfay added a commit that referenced this pull request Nov 8, 2017
* 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
@rickmanelius rickmanelius mentioned this pull request Nov 20, 2017
6 tasks done
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

Successfully merging this pull request may close these issues.

4 participants