Closed (won't fix)
Project:
Drush
Version:
8.x-6.x-dev
Component:
Core Commands
Priority:
Normal
Category:
Feature request
Assigned:
Issue tags:
Reporter:
Created:
10 Dec 2012 at 15:40 UTC
Updated:
11 Sep 2013 at 11:36 UTC
Jump to comment: Most recent file
Comments
Comment #1
greg.1.anderson commentedThere is a
__drush_ps1()function in drush.complete.sh that you can add to your PS1 to show your active site alias right on your prompt.I think that patches that add git-style active indicators (prefix each line with "* " or " ") would be considered favorably.
Comment #2
benjifisher@greg.1.anderson:
Thanks for the hint. It can be frustrating to submit a patch and get no attention.
Patch attached. It provides git-style indicators, as suggested. If no site alias has been set, then there is no change.
When testing, remember that if you set a remote alias, then "drush sa" is executed remotely.
Note: My guess was that "drush use" kept a stack of site aliases. After looking at the code, I see that it keeps only the current alias and one alternative.
Comment #3
benjifisherI have had two thoughts since writing the patch in #2:
site-alias(sa) command, or maybe thesite-set(use) command. Anyplace else?drush use -. The only question is what marks to use for the active and alternate site aliases: * (or + or =) and -? Or maybe (following vim) % and #?Or maybe you prefer to keep it the way it is.
I meant to note earlier that the patch in #2 has no effect if
site-aliasis invoked with the--tableor--fulloptions.Comment #4
greg.1.anderson commentedI think this is okay with the addition of the suggested documentation. I'd also be okay with the "-" on the previous alias, if desired.
Comment #5
benjifisherThe attached patch adds a line or two to the help text, as suggested in #3, and marks the previous alias with "-".
When testing, beware of remote aliases (see #2).
Comment #6
moshe weitzman commentedComment #7
greg.1.anderson commentedThis should be reworked once #1866344: Make --pipe awesome with output format engines lands. The other alias marker should be placed one of the table columns, and the default format should be table. Other format types should be supported.
I'm tempted to just close this and fix it with #1866344, but will keep it open for now.
Comment #8
moshe weitzman commented[ #1866344] has landed. I guess work here can proceed? I agree with the initial suggestion for folks to customize their bash prompt. It is really the best way.
Comment #9
benjifisherDo you mean the suggestion to use
__drush_ps1()in #1? That is already implemented (unless it was removed after 7.x-5.8).Personally, I think that my bash prompt is already too long. I do not want to add more to it. The time I want to see this information is when I look at my site aliases.
If people think that adding "* " for the current site alias and "- " for the previous alias (and " " for all others), then I will have a look at re-rolling the patch in #5.
Comment #10
greg.1.anderson commentedIf you run
drush sa --format=tableon the latest 8.x-6.x-dev, you will get a tabular output with fields for the alias id, root, uri, host and user (the last two for remote aliases only). This table is too wide for most terminal windows, and probably would not make a good default format.It would be easy enough to add a new field to the site-alias command that indicated the last and next-to-last aliases used. I think that "*" for the last alias and "-" for the next-to-last (with empty for the others) would be just fine.
I'm not sure what the default format should be for the sa command, but if you made the default format 'table' and the default fields the last-alias marker and the alias ID, that would give a result in line with what was suggested previously. If you then ran sa with the --full option, you'd get more fields, in line with the current --format=table output, so I think that would probably work out.
Comment #11
moshe weitzman commented@Benji - Care to implement #10? This requires some knowledge of output formats. Would be great if you and others became familiar with this new system.
Comment #12
greg.1.anderson commentedUnassigning. I'll help answer questions; see drush topic docs-output-formats for an introduction.
Comment #13
benjifisher@Moshe: thanks for reminding me about this. Yes, I think I can implement it.
@greg.1.anderson: I had a look at the docs. No questions so far; thanks for the offer.
Comment #14
benjifisherOK, I do have some questions. I think some of the documentation is incomplete, but maybe I am misreading it or my environment may be funny.
I checked out the latest 8.x-6.x branch and "drush cc drush". I do not have a drush config file on this machine. (At least, that is what "drush st" tells me.)
According to "drush help sa",
but "drush sa --pipe" gives me the simple list I am used to (same as "drush sa") whereas using "--format=var_export" gives what is described in
drush topic docs-output-formats. Is this a bug?According to
drush topic docs-output-formatsIt appears that "config" can be overridden by specifying (for example)
'variable-name' => 'aliases',in the'outputformat'array. (Seesitealias_drush_command())What does the
'field-mappings'key do?According to
drush help sa, the default format is "config", but "drush sa --format=config" gives something different from "drush sa".Changing the
'default'key in the'outputformat'array (say to "table") does not seem to have any effect.Comment #15
benjifisherI can answer some of my own questions.
drush sa @devthen--pipebehaves almost as expected. The only difference between--pipeand--format=var_exportis that the latter ends with an additional newline.'variable-name'does work as I thought.'field-mappings'does.drush sa @dev'default'key affectsdrush sa @devIn short, the documentation on formats for
drush saapplies if I give it an argument.I even found out where the output format is changed if I do not give any arguments: the line
in
_drush_sitealias_user_specified_list().New questions:
'list'to'table'here, I get tabular output by default, but with the default fields (Name, Root, URI, Host, User). The second argument todrush_set_default_outputformat()does not seem to make any difference. For example, I triedarray('#name' => 'Foo')and I tried adding a'fields-default'key. How can I specify which fields to display?Comment #16
moshe weitzman commented3. I think that field-mappings is a lookup instruction. see its usage at http://api.drush.org/api/drush/includes!output.inc/function/drush_rows_o...
1. I don't that it matters much where this line is. Go ahead and move it if you wish.
2. This is controlled by the 'fields-default' key in the command definition. I confirmed by addeding uri to this array and then --format=table started printing out the uri from a site alias. Arguably that should be in the default fields.
Comment #17
moshe weitzman commentedsite-alias command gets slightly complex with outputformat because it does two things depending if an argument was provided: list or detail. This is a common pattern - see test-run, watchdog-list/watchdog-show, queue-list/queue-run, and views-list/views-execute. Maybe we should add a site-list command and require folks to use that for site alias listings? If we go that route, it makes sense to split our part of test-run into a new test-list command.
Thoughts?
Comment #18
greg.1.anderson commentedRight now, site-alias in default (list) mode is a lot slower than it needs to be, because the site-alias command does not know (does not check) how its output format will handle the data. In list mode, only the array key is needed, but the full data structure is produced, because the implementation is very general-purpose. If we had a site-list command, it could execute more effectively.
Despite that fact, from a UX point of view, I wouldn't really want to have a bunch of *-list variants for all commands that are like this. If we did implement the commands like this for performance reasons, maybe we could intelligently have the command dispatcher switch from the 'site-alias' command to the 'site-alias-list' command (which is aliased to 'site-list' and 'sl') iff the selected output format is a simple list.
Just thinking aloud; not sure of the best solution.
Comment #19
moshe weitzman commentedI like the command dispatcher approach. I think site-alias-list could be a hidden command. I can take this on. If this turns out well, we'd want to unify those other commands I mentioned on the same approach.
@benjifisher - sorry to hijack your issue a bit. feel free to continue mulling how we implement the site-set marker and what the default fields should be for a listing.
Comment #20
benjifisherMoshe:
Hijack away. I think that I have done my job as a beta tester--which is pretty much what you asked for in #11--if I ask good questions and you end up doing the implementation. In the mean time, worrying about the
'field-mappings'key led me to submit #2047241: drush_lookup_field_by_path() always returns empty string if $path is an array and #2047209: Document $mapping in drush_lookup_field_by_path() and 'field-mappings' in drush_rows_of_key_value_to_array_table().I agree. We design things differently if they are intended to be used interactively. Think vi regular expressions vs. PCRE.
This would be easy to fix. Just change the code at the point where you check whether any arguments were passed.
I think the real difficulty with this issue, as I explored in #14 and #15 and Moshe summarized in #17, is that
drush saanddrush sa @devare really two commands, with different default formats. Right now, that is accomplished withdrush_set_default_outputformat(). (This function does not work the way I expect, which may or may not mean that it simply does not work.) I think a cleaner approach is to use two different commands internally, so that each can have its own set of defaults. IIUC, this is what you have in mind with "the command dispatcher approach."Comment #21
moshe weitzman commentedI don't think we can speed things up here. We want the ability to show a table or csv for a listing that has root/uri etc.
So, I started to implement the original feature request here and ran into a snag. When you have used site-set, all your commands are targetted to the remote site - even site-list! So, you won't ever see a site marked as being active. We could probably force sa command to always operate locally, but I don't think thats wise.
When I was testing this, I once again smiled as my bash prompt told me what site was active. I really encourage folks to source our drush.complete.sh script and then use the __drush_ps1() function in their PS1. This is documented in the README.
Not sure there is anything more we should do here.
Comment #22
greg.1.anderson commentedHm, yes, it would be easy enough to flag the site-list command to always run locally, like ssh does. I think that overall that would be a big improvement, but it would be a source of frustration to anyone who actually did want to run the site-list command remotely, to see what sites are defined on a different machine.
Maybe what we need here is a command-exception list for site-set, so that site-list runs locally when you've set the site to a remote machine, but you can still use
drush @remote site-listto inspect the aliases on the remote machine.It would be good if this level of functionality were supported if we implement the proposal in this issue. I agree that relying on __drush_ps1 works well, and sidesteps the oddities with site-list nicely.
Comment #23
moshe weitzman commentedToo complicated. I'm back to recommending the custom prompt.
Comment #24
greg.1.anderson commentedFine by me. I can't think of another command that would want to use the facility described in #22.
Comment #25
benjifisherFor example, @dev is remote. I do not know if it matters, but locally I am running 6.x from git and the remote server is running 5.9. Real example:
Note the prompts. (Disclaimer: I edited out the part of the prompt that is not relevant to this discussion.)
Comment #26
greg.1.anderson commented#25 does look like a bug; you are correct that drush use should always run locally. Please note that we already have a facility to set certain commands to always run locally; the enhancement in #22 was a suggestion to make a command run either remotely or locally depending on -how- the remote site alias was specified.
Comment #27
moshe weitzman commentedI just committed the one line fix to make site-set always run locally.
I added same line to site-alias and branched the current code as follows below. I ran out of time and brain power for this tonight. Not sure I will finish it. I'm having trouble finding the right conditions under which we should drush_invoke_process():
Comment #28
greg.1.anderson commented#27 looks about right to me in concept. I don't have time to run it to see if there are any actual operational problems with it; you imply that there is some trouble, but it looks like it must be pretty close to right to me.
Comment #29
greg.1.anderson commentedThis issue was marked
closed (won't fix)because Drush has moved to Github.If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to
closed (duplicate).Please ask support questions on Drupal Answers.