クラッピーをAA化してclappy-sayしてみる

#クラッピーチャレンジ Advent Calendar 2017 19日目の記事です

最近コンソールばっかり眺めているので、コンソールで利用可能なクラッピーを作る。


## 出来上がったもの

``` text
# docker run -it miyatama/clappysay:latest cowsay 'PACHI-PACHI!!'
 _______________
< PACHI-PACHI!! >
 ---------------
    \
     \
      \
                     ...(+ggggmmgMMM#Y7WK-
                   .dHBBY9C(JdHWHH=?5^ ?WN-..
                  .dD    .(MY|      .&_ (#9TXx
               ..+W3^   (dMC^   .-. (m{ (M0<dR
               (N0|    jW9?O&_ .Xk< (H{ (HZ>dP
               (#C^    dS:  dr  XMr (@}^(WZ>dR
               (#_     d0<  dr  (Mr .g} (WZ>dR
               (#_     dS:  dr   dr .@} (WZ<db
               (#_     dS:  dr   dr .Hl.(WZ|db
               (#_     dS:  dm,  d& .TMr(Wk~db
               (#_     dK<  dMb  dHl .dr(WN{dNm..
               (#_     dK:   db  jXI  dr.?M{d#'TQ+.
               (#_     dD|   dD  jXI .dr .g{db .dk=
               (#_     d&   ^_^  (<|^ d3  7^db.dHC~
               (#_     dr                     .HC
               (#_     dr                    .s=
               (#_     dR-                   (#|
               (#_     dK<                   (#~
               (#_     dK<                   (#~
               (#_     dK<                   (#~
               (#_     dK:                   (#_
               (Ms.    dK<                   (#_
               (WI_    dK:                   (#|
               (Uk~    dS:                   J#~
                .g{    dm2                  (y=
                 OW{    db.                .dD
                  dm&^  ?XK_              (&M
                   ?B+.  (MH_           .(H&|
                    _7Qg+ _7_          (w=|
                    ..(dMb  dMWWMo.   dm+
                  .(dMY7?|  d& .XMr   ?7Xme-
                .XY=| ^   .-dr  dMr      .TYWx.
               (mkodkkkkkQNNC~ .(MR-.       _jR-.
              jMMMB^     (YWMmgMMMMM8+J,      .m{
             jM#&^          d&|~~~~_.?HNs      ?dl
             dMb           .-gy   (d#_ ?Wp.     dHm
          .jHMMMHNo((JWNNNNMMMD   .dMNHMM#-      dM
        (+gMNmgggMMMM#YTMM#Y7|.+&gd9''|?TN0~     dM
     ..WM=^^^_~_~~<VME~ _^^.(dME|^    .dKC^     .dM
    (Q8|               ^.(gWY|        d8>      Jdf7
  .jW&                 (d9|           dH>  ..(d9:
 .dMNe-              .gV|             dNo.JdMM#_
 dMM%(9&.  ....,    (MB|              7WB9=^ J#_
 MMM&(jM{.(kZWMK.  (d@~                     ^j#_
 |BWa+@| dNdMM&J#_.dD                        J#_
 |-(<|^  (X#C1dS> qHC                        J#_
 MMMNmJJ..(TYY=  .dr                         J#_
 |I?7HMMMNms.    zW{                         J#_
 MNa&J-_?7TY^    zW>                         J#_
 Mz~?TMMHm&-     zW{                         (#~
 zH:   ?77'^     zX{                         (#_
  ?WHm.           dr                .k:      (#~
    ?74Qa-        ?Gx             .(gN{      (#~
       <?THK-  ..  ?WN-..........dH9UM{      (#~
           |_jdQmggx(?7HNNQQQM@?7?  (H{      (#~
               (#C|7YWMHY3  dD|    (MN{      (#~
               (#~   .Hl_   dr     (#=       (#~
               (#_   .H2    dr     (#_       (#~
               (#_   .@}    dr     (#_       (#~
               (#_   .@|    dr     (#_       (#~
               (#_   .g{    dr     (#_       (#~
              .d#_   .g{    dr     (#_       (#_
              JH8    .@|    dr    .d#_       (#|
              JR<   .gN{   .Mr    (d#        (#_
              dR<   (MB:   (Mr    (d@        (N+.
              dK    (#_    (Wr    (d@        (MN:
              db    (#_   .(Wr    (d@.       (MM:
              dN+-. (#_ .(kS7|    (d@        (#>
               (TMNmuNad#Y|       (dK.      .j#~
                .MMYvM=?          jH@     .gH8|
                .MH>              dM&    .H9:
                .Xb>              d@   .jKC
                .WNl              db .(Z=
                  ?THR...         vD.X:
                    _TYYWaJ..  .J+JJY
                         (dMNNNNkZ>

```

作っといて何だけど、ちっさいAAが欲しい。

一応gitにも上げた。[miyatama/clappysay](https://github.com/miyatama/clappysay)

## 作る過程

### AA化する

おもむろにクラッピーの画像をダウンロードし、
[ココ](https://mementoo.info/archives/1773)とか[ココ](https://tool-taro.com/image_to_ascii/)でAA化する。

![clappy_04.png](https://qiita-image-store.s3.amazonaws.com/0/42445/4f210a9d-1dee-e940-cc50-2af44cc563ad.png)

でかい。


### whalesayを改造してclappysayを作る

dockerインストールしておもむろにpull

``` bash
docker pull docker/whalesay:latest
```

AA化したクラッピーをclappy.cowとして保存し、imageに取り込む。

``` dockerfile
FROM docker/whalesay:latest

COPY clappy.cow /usr/local/share/cows/clappy.cow

RUN rm -f /usr/local/share/cows/default.cow \
  && ln -sv /usr/local/share/cows/clappy.cow /usr/local/share/cows/default.cow

CMD ["cowsay"]
```

ビルドして実行

``` bash
docker build -t miyatama/clappysay:latest .
docker run miyatama/clappysay:latest cowsay complete
```

やったね！エラーだ！

``` text
cowsay: Unterminated <> operator at /usr/local/share/cows/default.cow line 10.
```

### エラーをとる

clappy.cowの中身的にヒアドキュメントっぽい。
何のヒアドキュメントなのか不明なのでcowsayの中を見てみる。

``` perl
#!/usr/bin/perl

##
## Cowsay 3.03
##
## This file is part of cowsay.  (c) 1999-2000 Tony Monroe.
##

use Text::Tabs qw(expand);
use Text::Wrap qw(wrap fill $columns);
use File::Basename;
use Getopt::Std;
use Cwd;
```

cowsay...お前perlだったのか...

とりあえずperlのヒアドキュメントがどんなものなのか見てみる

 + [Perlヒアドキュメント](https://qiita.com/gosshys/items/1e4c1d6bb0099b80701a)

とりあえず、エラーになりそうなやつを置き換える

 + $
 + @{

よし出た

``` text
docker run -it miyatama/clappysay:latest cowsay miyatama
c7ee9840a46d
c7ee9840a46d
 __________
< miyatama >
 ----------
    \
     \
      \
                     ...(+ggggmmgMMM#Y7WK-
                   .dHBBY9C(JdHWHH=?5^ ?WN-..
                  .dD    .(MY|      .&_ (#9TXx
               ..+W3^   (dMC^   .-. (m{ (M0<dR
               (N0|    jW9?O&_ .Xk< (H{ (HZ>dP
               (#C^    dS:  dr  XMr (@}^(WZ>dR
               (#_     d0<  dr  (Mr .g} (WZ>dR
               (#_     dS:  dr   dr .@} (WZ<db
               (#_     dS:  dr   dr .Hl.(WZ|db
               (#_     dS:  dm,  d& .TMr(Wk~db
               (#_     dK<  dMb  dHl .dr(WN{dNm..
               (#_     dK:   db  jXI  dr.?M{d#'TQ+.
               (#_     dD|   dD  jXI .dr .g{db .dk=
               (#_     d&   ^_^  (<|^ d3  7^db.dHC~
               (#_     dr                     .HC
               (#_     dr                    .s=
               (#_     dR-                   (#|
               (#_     dK<                   (#~
               (#_     dK<                   (#~
               (#_     dK<                   (#~
               (#_     dK:                   (#_
               (Ms.    dK<                   (#_
               (WI_    dK:                   (#|
               (Uk~    dS:                   J#~
                .g{    dm2                  (y=
                 OW{    db.                .dD
                  dm&^  ?XK_              (&M
                   ?B+.  (MH_           .(H&|
                    _7Qg+ _7_          (w=|
                    ..(dMb  dMWWMo.   dm+
                  .(dMY7?|  d& .XMr   ?7Xme-
                .XY=| ^   .-dr  dMr      .TYWx.
               (mkodkkkkkQNNC~ .(MR-.       _jR-.
              jMMMB^     (YWMmgMMMMM8+J,      .m{
             jM#&^          d&|~~~~_.?HNs      ?dl
             dMb           .-gy   (d#_ ?Wp.     dHm
          .jHMMMHNo((JWNNNNMMMD   .dMNHMM#-      dM
        (+gMNmgggMMMM#YTMM#Y7|.+&gd9''|?TN0~     dM
     ..WM=^^^_~_~~<VME~ _^^.(dME|^    .dKC^     .dM
    (Q8|               ^.(gWY|        d8>      Jdf7
  .jW&                 (d9|           dH>  ..(d9:
 .dMNe-              .gV|             dNo.JdMM#_
 dMM%(9&.  ....,    (MB|              7WB9=^ J#_
 MMM&(jM{.(kZWMK.  (d@~                     ^j#_
 |BWa+@| dNdMM&J#_.dD                        J#_
 |-(<|^  (X#C1dS> qHC                        J#_
 MMMNmJJ..(TYY=  .dr                         J#_
 |I?7HMMMNms.    zW{                         J#_
 MNa&J-_?7TY^    zW>                         J#_
 Mz~?TMMHm&-     zW{                         (#~
 zH:   ?77'^     zX{                         (#_
  ?WHm.           dr                .k:      (#~
    ?74Qa-        ?Gx             .(gN{      (#~
       <?THK-  ..  ?WN-..........dH9UM{      (#~
           |_jdQmggx(?7HNNQQQM@?7?  (H{      (#~
               (#C|7YWMHY3  dD|    (MN{      (#~
               (#~   .Hl_   dr     (#=       (#~
               (#_   .H2    dr     (#_       (#~
               (#_   .@}    dr     (#_       (#~
               (#_   .@|    dr     (#_       (#~
               (#_   .g{    dr     (#_       (#~
              .d#_   .g{    dr     (#_       (#_
              JH8    .@|    dr    .d#_       (#|
              JR<   .gN{   .Mr    (d#        (#_
              dR<   (MB:   (Mr    (d@        (N+.
              dK    (#_    (Wr    (d@        (MN:
              db    (#_   .(Wr    (d@.       (MM:
              dN+-. (#_ .(kS7|    (d@        (#>
               (TMNmuNad#Y|       (dK.      .j#~
                .MMYvM=?          jH@     .gH8|
                .MH>              dM&    .H9:
                .Xb>              d@   .jKC
                .WNl              db .(Z=
                  ?THR...         vD.X:
                    _TYYWaJ..  .J+JJY
                         (dMNNNNkZ>

```