Here is a stab at a new command, 'views tag', which is actually two commands: 'views tag list' and 'views tag export'
The itch I wanted to scratch here is a command line tool for the bulk export workflow which I thinks is pretty common:
1. Create you views for a module called "your_module"
2. Tag them with "your_module"
3. Go to Tools, Bulk export. Filter by the tag, select all views, type in the modules name and export.
4. Copy and paste the result to your_module.views_default.inc
With 'views tag export' step 3 and 4 can be done with the following command, where the export result from STDOUT is piped to the appropriate file:
views tag export your_module > your_module/includes/your_module.views_default.inc
'views tag list' list tags and optionally the name of the views. 'views tag' is a shorthand for 'views tag list'. See the documentation for some more options.
| Comment | File | Size | Author |
|---|---|---|---|
| drush_views_tag.patch | 3.76 KB | anders.fajerson |
Comments
Comment #1
pescetti commentedComment #2
jonskulski commentedHey, started checking our your module. I suggest consolidating commands for this. Perhaps supporting a --tag flag with an implicit assuming of --name.
For example,
Where as the following are equivalent
Would keep the name space cleaner :)
Comment #3
anders.fajerson commentedI agree that it could make sense to add this to the export command. One problem though, if I remembered it correctly, is that the current views export command is fundamentally different from my approach (it creates files instead of printing to STDOUT), so mixing them together could potentially be confusing.
Comment #4
pescetti commentedI plan to implement, reusing but refactoring this code (btw, thanks fajerstarter for a nice idea and implementation), two different commands:
The former would create files like the original design, the latter would output to STDOUT in the format this patch uses (including the
<?phpheader and so on).Ideally, both would accept similar options, so we would have:
There is some ongoing work in the dev version (where
drush views tagis disabled since it will be exposed through these commands) , and I will post here once it's done. But I welcome feedback, or, why not, patches in this direction.Comment #5
anders.fajerson commentedSounds excellent. I missed that you've committed the code. I'm now subscribed to the CVS RSS feed!
Comment #6
anders.fajerson commentedJust a comment on the naming of the new commands. When I first read the commands without reading pescetti's explanation I envisioned "drush views export" would be my approach (STDOUT) and "drush views dump" be the one that dumped the views to files. My thinking is that an views export command should be similar to what you do in the views admin UI, and there I think printing to STDOUT is more in line with exporting a view to a textarea.
Comment #7
jonskulski commentedI know 'ls' detects whether it is printing to STDOUT or is piped to a file, so you maybe able to do a similar thing and leverage it and avoid expanding the name space. I suppose that is a very unixy solution.
Comment #8
mvc@pescetti your plan to allow exporting to stdout or a file, with an optional --tag argument for either case, makes sense to me. i would personally suggest defaulting to printing to stdout, with another optional argument --output or maybe --path which specifies a filename, in which case output would go there.
you could also use two command names, export and dump, to indicate whether or not to print the "function default_views_default_views()" header. i would add another optional argument to use a different function name, too.
if you think that sounds like a good approach, i would sit down and write this now, although fajerstarter's comment above makes me think you've actually written some code and committed it someplace -- i don't see any updates at http://drupalcode.org/viewvc/drupal/contributions/modules/drush_views/ in the past 9 months, though. if you like my ideas, i'll get started!
Comment #9
anders.fajerson commented@mvc Current development is at the 6.x-2 branch. Here are the CVS messages: http://drupal.org/project/cvs/393338.
My patch has been committed but nothing yet on the new proposed syntax in #4.
Comment #10
pescetti commentedI'm generalizing this issue so it better fits the ongoing discussion: let's use it to decide the new module syntax.
Comments received so far expose the following needs:
There are two points not to forget:
A starting point to discuss the new syntax follows.
This exports views as single files in the specified directory (if
--target-pathis omitted, a default path is used).The views to be exported can be specified by a tag (or a list of tags) or by name: if neither is specified, all views are exported; otherwise, all views having one of the listed tags or names are exported.
Shares the same syntax as
drush views exportbut exports views as a stream to stdout. No options are provided to generate a file, standard output redirection will be used.An extra option is provided for
drush views dump, i.e.,--module. I'm not sure about the name. The idea is that this function will generate the code (basically, the short header with proper function name) for theMODULE.views_default.incfile contents, so the call would be:The
importcommand would be mostly unchanged, and be the counterpart ofexport.For symmetry, we would need a
restorecommand that is the counterpart ofdumpbut unless someone sees a practical use case for it I think it's redundant: import in this case is done by enabling the relevant module.I welcome everybody's comments on this draft: I'd like to see consensus on the new syntax before I (or we!) proceed with the implementation.
Comment #11
mvcThat draft sounds great to me, especially the ability to set the name of the module, although I assume you meant:
drush views dump --module=my_module [arguments] > my_module.views_default.inc
I'm not that picky about the syntax personally, as long as the functionality is present.
I would be very happy to help with this, for example by testing if you're already planning to go ahead and write this.
Comment #12
pescetti commentedDevelopment branch 3.x-dev started and this issue better fits there. I made minimal changes to the specification to match the Drush 3.x syntax and fix the typo spotted by mvc.
Comment #13
xjmTracking.
Comment #14
xjmRe: #10, I can see the value of having all the views in one file, but I'm not sure it fits all situations. I'd prefer the option to export them as individual include files (with PHP header and so forth).
I export my views entirely for the purpose of keeping them in version control, and in this circumstance it's desirable to have one include per view so that I can version each view individually (as described in #671062: Closing the Circle: How to use drush views export for something that hook_views_default_views() can use). If anything, my views are specific to a particular site, not a particular module; the module I use to include them is just a catch-all.
In either situation, I'd recommend appending a line with
// $Id$after the opening PHP tag so that the generated view file is friendly to the the d.o packaging script.Comment #15
sethcohn commented+1 to xjm's comment in #14. Please see the other issue's patch for code that works well for this use case.
Comment #16
jsenich commentedSubscribe.
Comment #17
k4ml commentedFor starter, maybe we can at least print the output to STDOUT. This actually my initial expectation when testing this module. Then anyone can use their own favorite unix tools to do the further work. For example, I can do drush views-export | append_php.sh > views_export_someviewname.inc since I prefer to have my views in a separate include files rather than one big my_module.views_default.inc.
Comment #18
voxpelli commented+1 on #17 - subscribing
Comment #19
pescetti commentedThanks, this functionality is now committed to the 3.x branch, with a more general syntax than the one outlined here.
You will use something like:
drush vwex --tag=og,atrium --output=bulk --module=modulenameto produce a bulk export on STDOUT containing all views tagged "og" or "atrium"; the exported code will define a function named
modulename_views_default_views().