| 1 | package App::Zealc::Command::download; |
| 2 | |
| 3 | use 5.014000; |
| 4 | use strict; |
| 5 | use warnings; |
| 6 | |
| 7 | our $VERSION = '0.000_001'; |
| 8 | |
| 9 | use App::Zealc '-command'; |
| 10 | |
| 11 | use File::Spec::Functions qw/rel2abs/; |
| 12 | |
| 13 | use Term::ANSIColor qw/:constants/; |
| 14 | use Term::FormatColumns qw/format_columns/; |
| 15 | use Zeal::Feed; |
| 16 | |
| 17 | use constant FEEDS => [qw/NET_Framework ActionScript ColdFusion Akka Android AngularJS Ansible Apache_HTTP_Server Appcelerator_Titanium AppleScript Arduino AWS_JavaScript BackboneJS Bash Boost Bootstrap_2 Bootstrap_3 Bourbon C CakePHP Cappuccino Chai Chef Clojure CMake Cocos2D Cocos3D CodeIgniter CoffeeScript Common_Lisp Compass Cordova Corona CSS D3JS Dart Django Dojo DOM Drupal_7 Drupal_8 ElasticSearch Elixir Emacs_Lisp EmberJS Emmet Erlang Express ExpressionEngine ExtJS Flask Font_Awesome Foundation Git GLib Go Grails Groovy Groovy_JDK Grunt Haml Haskell HTML iOS Jade Jasmine Java_EE6 Java_EE7 Java_SE6 Java_SE7 Java_SE8 JavaFX JavaScript Joomla jQuery jQuery_Mobile jQuery_UI KnockoutJS Kobold2D LaTeX Laravel Less Linux_Man_Pages Mac_OS_X Man_Pages MarionetteJS Markdown Meteor MomentJS MongoDB Mongoose Mono MooTools MySQL Neat Nginx NodeJS NumPy OCaml OpenCV_C OpenCV_Java OpenCV_Python OpenGL_2 OpenGL_3 OpenGL_4 Perl PhoneGap PHP PHPUnit Play_Java Play_Scala PostgreSQL Processing PrototypeJS Puppet Python_2 Python_3 Qt_4 Qt_5 R Redis RequireJS Ruby Ruby_2 Ruby_on_Rails_3 Ruby_on_Rails_4 RubyMotion Rust SaltStack Sass Scala SciPy Sencha_Touch Sinon Smarty Sparrow Spring_Framework SproutCore SQLAlchemy SQLite Statamic Stylus SVG Swift Symfony Tcl Tornado Twig Twisted TYPO3 UnderscoreJS Unity_3D Vagrant Vim VMware_vSphere WordPress Xamarin Xojo XSLT XUL Yii YUI Zend_Framework_1 Zend_Framework_2 ZeptoJS/]; |
| 18 | |
| 19 | my %feeds = map { y/A-Z_/a-z-/r => $_ } @{FEEDS()}; |
| 20 | |
| 21 | sub usage_desc { "%c download %o\n%c download %o DOCSET\n%c download URL_TO_FEED" } |
| 22 | |
| 23 | sub validate_args { |
| 24 | my ($self, $opts, $args) = @_; |
| 25 | my @args = @$args; |
| 26 | $self->usage_error("Too many arguments") if @args > 1; |
| 27 | } |
| 28 | |
| 29 | sub _show_docset { |
| 30 | my ($file) = @_; |
| 31 | return $_ unless -d $file; |
| 32 | return BOLD . "$_*" . RESET if -t select; |
| 33 | return "$_*"; |
| 34 | } |
| 35 | |
| 36 | sub execute { |
| 37 | my ($self, $opts, $args) = @_; |
| 38 | my ($name) = @$args; |
| 39 | if (!$name) { |
| 40 | my @feeds = map { |
| 41 | my $fname = $feeds{$_} =~ y/_/ /r; |
| 42 | my $file = rel2abs "$fname.docset", $self->app->path; |
| 43 | _show_docset $file |
| 44 | } sort keys %feeds; |
| 45 | print format_columns @feeds; |
| 46 | } else { |
| 47 | my $feed = Zeal::Feed->new(exists $feeds{$name} ? "http://kapeli.com/feeds/$feeds{$name}.xml" : $name); |
| 48 | say "Downloading $feeds{$name} version ", $feed->version, ' from ', $feed->url; |
| 49 | $feed->download($self->app->path); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | 1; |
| 54 | __END__ |
| 55 | |
| 56 | =encoding utf-8 |
| 57 | |
| 58 | =head1 NAME |
| 59 | |
| 60 | App::Zealc::Command::download - view available docsets and download them |
| 61 | |
| 62 | =head1 SYNOPSIS |
| 63 | |
| 64 | zealc download |
| 65 | # <list of docsets> |
| 66 | |
| 67 | zealc download latex |
| 68 | # Downloading LaTeX version /1 from http://london3.kapeli.com/feeds/LaTeX.tgz |
| 69 | |
| 70 | zealc download http://kapeli.com/feeds/LaTeX.xml |
| 71 | # Downloading LaTeX version /1 from http://london3.kapeli.com/feeds/LaTeX.tgz |
| 72 | |
| 73 | =head1 DESCRIPTION |
| 74 | |
| 75 | When invoked with no arguments, the download command displays a list |
| 76 | of known Dash docsets. The installed docsets have a * after their |
| 77 | name. |
| 78 | |
| 79 | When invoked with an argument from the list of known Dash docsets it |
| 80 | downloads that docset. |
| 81 | |
| 82 | When invoked with an argument not from the list of known Dash docsets |
| 83 | it assumes the argument is a link to a L<Zeal::Feed> and downloads the |
| 84 | docset described by the feed. |
| 85 | |
| 86 | =head1 SEE ALSO |
| 87 | |
| 88 | L<zealc>, L<Zeal> |
| 89 | |
| 90 | =head1 AUTHOR |
| 91 | |
| 92 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> |
| 93 | |
| 94 | =head1 COPYRIGHT AND LICENSE |
| 95 | |
| 96 | Copyright (C) 2015 by Marius Gavrilescu |
| 97 | |
| 98 | This library is free software; you can redistribute it and/or modify |
| 99 | it under the same terms as Perl itself, either Perl version 5.20.1 or, |
| 100 | at your option, any later version of Perl 5 you may have available. |
| 101 | |
| 102 | |
| 103 | =cut |