| 1 | package Mojolicious::Command::badge; | ||
| 2 | use Mojo::Base 'Mojolicious::Command'; | ||
| 3 | |||
| 4 | use Mojo::Util qw(getopt); | ||
| 5 | |||
| 6 | has description => 'Create a badge'; | ||
| 7 | has usage => sub { shift->extract_usage }; | ||
| 8 | |||
| 9 | sub run { | ||
| 10 | my ($self, @args) = @_; | ||
| 11 | |||
| 12 | getopt \@args, | ||
| 13 | 'color=s' => \my $color, | ||
| 14 | 'embed-logo' => \my $embed_logo, | ||
| 15 | 'file=s' => \my $file, | ||
| 16 | 'format=s' => \my $badge_format, | ||
| 17 | 'label-color=s' => \my $label_color, | ||
| 18 | 'label-link=s' => \my $label_link, | ||
| 19 | 'label-text-color=s' => \my $label_text_color, | ||
| 20 | 'label-title=s' => \my $label_title, | ||
| 21 | 'label=s' => \my $label, | ||
| 22 | 'link=s' => \my $link, | ||
| 23 | 'logo=s' => \my $logo, | ||
| 24 | 'message-link=s' => \my $message_link, | ||
| 25 | 'message-text-color=s' => \my $message_text_color, | ||
| 26 | 'message-title=s' => \my $message_title, | ||
| 27 | 'message=s' => \my $message, | ||
| 28 | 'style=s' => \my $style, | ||
| 29 | 'title=s' => \my $title; | ||
| 30 | |||
| 31 | if (!$label) { | ||
| 32 | say $self->usage; | ||
| 33 | exit 1; | ||
| 34 | } | ||
| 35 | |||
| 36 | my %options = (); | ||
| 37 | |||
| 38 | $options{label} = $label; | ||
| 39 | $options{message} = $message; | ||
| 40 | $options{color} = $color; | ||
| 41 | |||
| 42 | $options{badge_format} = $badge_format if ($badge_format); | ||
| 43 | $options{style} = $style if ($style); | ||
| 44 | $options{link} = $link if ($link); | ||
| 45 | $options{title} = $title if ($title); | ||
| 46 | $options{logo} = $logo if ($logo); | ||
| 47 | $options{embed_logo} = 1 if ($embed_logo); | ||
| 48 | |||
| 49 | $options{label_color} = $label_color if ($label_color); | ||
| 50 | $options{label_link} = $label_link if ($label_link); | ||
| 51 | $options{label_text_color} = $label_text_color if ($label_text_color); | ||
| 52 | $options{label_title} = $label_title if ($label_title); | ||
| 53 | |||
| 54 | $options{message_link} = $message_link if ($message_link); | ||
| 55 | $options{message_text_color} = $message_text_color if ($message_text_color); | ||
| 56 | $options{message_title} = $message_title if ($message_title); | ||
| 57 | |||
| 58 | my $badge = eval { $self->app->badge(%options) }; | ||
| 59 | |||
| 60 | if ($@) { | ||
| 61 | say "[ERROR] $@"; | ||
| 62 | exit 255; | ||
| 63 | } | ||
| 64 | |||
| 65 | unless ($file) { | ||
| 66 | say $badge; | ||
| 67 | return 0; | ||
| 68 | } | ||
| 69 | |||
| 70 | Mojo::File->new($file)->spurt($badge); | ||
| 71 | return 0; | ||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 | 1; | ||
| 76 | |||
| 77 | =encoding utf8 | ||
| 78 | |||
| 79 | =head1 NAME | ||
| 80 | |||
| 81 | Mojolicious::Command::badge - Badge command | ||
| 82 | |||
| 83 | =head1 SYNOPSIS | ||
| 84 | |||
| 85 | Usage: APPLICATION badge [OPTIONS] | ||
| 86 | |||
| 87 | ./myapp.pl badge --label "Hello" --message "Mojo!" --color "orange" \ | ||
| 88 | --format png --file my-cool-badge.png | ||
| 89 | |||
| 90 | Options: | ||
| 91 | --label <string> The text that should appear on the left-hand-side | ||
| 92 | of the badge | ||
| 93 | --message <string> The text that should appear on the right-hand-side | ||
| 94 | of the badge | ||
| 95 | --color <string> Message color | ||
| 96 | --style <string> Badge style ("flat" [default], "flat-square", | ||
| 97 | "plastic" or "for-the-badge") | ||
| 98 | --format <string> Badge format ("svg" [default] or "png") | ||
| 99 | --title <string> The title attribute to associate with the | ||
| 100 | entire badge | ||
| 101 | --label-color <string> Label color | ||
| 102 | --label-title <string> The title attribute to associate with the left | ||
| 103 | part of the badge | ||
| 104 | --label-link <string> The URL that should be redirected to when the | ||
| 105 | left-hand text is selected | ||
| 106 | --label-text-color <string> Label text color | ||
| 107 | --message-title <string> The title attribute to associate with the right | ||
| 108 | part of the badge | ||
| 109 | --message-link <string> The URL that should be redirected to when the | ||
| 110 | right-hand text is selected | ||
| 111 | --message-text-color <string> Message text color | ||
| 112 | --link <string> Link for the whole badge (works only for SVG badge) | ||
| 113 | --logo <string> A file, URL or data (e.g. "data:image/svg+xml;utf8,<svg...") | ||
| 114 | representing a logo that will be displayed | ||
| 115 | inside the badge. | ||
| 116 | --embed-logo Includes logo in badge | ||
| 117 | --file <path> Write the badge in file | ||
| 118 | |||
| 119 | =head1 DESCRIPTION | ||
| 120 | |||
| 121 | L<Mojolicious::Command::badge> is a utility for create badges. | ||
| 122 | |||
| 123 | =head1 ATTRIBUTES | ||
| 124 | |||
| 125 | L<Mojolicious::Command::badge> inherits all attributes from L<Mojolicious::Command> | ||
| 126 | and implements the following new ones. | ||
| 127 | |||
| 128 | =head2 description | ||
| 129 | |||
| 130 | my $description = $job->description; | ||
| 131 | $job = $job->description('Foo'); | ||
| 132 | |||
| 133 | Short description of this command, used for the command list. | ||
| 134 | |||
| 135 | =head2 usage | ||
| 136 | |||
| 137 | my $usage = $job->usage; | ||
| 138 | $job = $job->usage('Foo'); | ||
| 139 | |||
| 140 | Usage information for this command, used for the help screen. | ||
| 141 | |||
| 142 | =head1 METHODS | ||
| 143 | |||
| 144 | L<Mojolicious::Command::badge> inherits all methods from L<Mojolicious::Command> | ||
| 145 | and implements the following new ones. | ||
| 146 | |||
| 147 | =head2 run | ||
| 148 | |||
| 149 | $job->run(@ARGV); | ||
| 150 | |||
| 151 | Run this command. | ||
| 152 | |||
| 153 | =head1 SEE ALSO | ||
| 154 | |||
| 155 | L<Mojolicious::Plugin::Badge>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||
| 156 | |||
| 157 | =cut |