コマンドラインツールについて語るときに僕の語ること #yapcasia

コマンドラインツールについて語るときに僕の語ること #yapcasia

Ecb3acc2d246962361a4f8b3f7a6dd12?s=128

taichi nakashima

August 29, 2014
Tweet

Transcript

  1. What I Talk about When I Talk about CLI Tool

    ίϚϯυϥΠϯπʔϧʹ͍ͭͯޠΔͱ͖ʹ๻ͷޠΔ͜ͱ https://www.flickr.com/photos/36247316@N00/3108399560
  2. I’m Taichi Nakashima @deeeet tcnksm https://www.flickr.com/photos/flcherb/7781533580

  3. https://www.flickr.com/photos/flcherb/7781533580

  4. https://www.flickr.com/photos/flcherb/7781533580

  5. https://www.flickr.com/photos/flcherb/7781533580

  6. What I Talk about When I Talk about CLI Tool

    ίϚϯυϥΠϯπʔϧʹ͍ͭͯޠΔͱ͖ʹ๻ͷޠΔ͜ͱ https://www.flickr.com/photos/36247316@N00/3108399560
  7. ຊൃදʹ͸ݸਓతͳࢥ૝ؚ͕·Ε͍ͯ·͢ Warning https://www.flickr.com/photos/flcherb/7781533580

  8. ຊൃදʹ͸Perlͷ࿩ؚ͕·Ε͍ͯ·ͤΜ Warning ͨͩɼ͋ΒΏΔݴޠͰ࣮ݱՄೳͳ࿩Λ͠·͢ https://www.flickr.com/photos/flcherb/7781533580

  9. Background https://www.flickr.com/photos/flcherb/7781533580

  10. https://www.flickr.com/photos/flcherb/7781533580 ੈͷதʹ͸ ྑ͍$-*πʔϧͱ ͦ͏Ͱͳ͍πʔϧ͕͋Δ

  11. https://www.flickr.com/photos/flcherb/7781533580 ͦͷࠩ͸୯७ͳ͜ͱΛ ࣮ફ͢Δ͜ͱͰॖΊΔ ͜ͱ͕Ͱ͖Δ ౰ͨΓલա͗ͯ͋·ΓޠΒΕͳ͍

  12. https://www.flickr.com/photos/flcherb/7781533580 ࣗ෼͸ԿΛ࣮ફ͍ͯ͠Δ͔ʁ

  13. طʹ࡞͍ͬͯΔͻͱ https://www.flickr.com/photos/flcherb/7781533580 ࡞ͬͨ͜ͱͳ͍ͻͱ → ݟ௚͠ͷػձʹ → ͙͢ʹΤσΟλΛ։͚ΔΑ͏ʹ

  14. lྑ͍z$-*πʔϧͱ͸ʁ ͍͔ʹlྑ͍z$-*πʔϧΛ࡞Γ࢝ΊΔ͔ʁ What is “Good” CLI tool ? How to

    start to create “Good” CLI tool ? https://www.flickr.com/photos/36247316@N00/3108399560
  15. lྑ͍z$-*πʔϧͱ͸ʁ ͍͔ʹlྑ͍z$-* What is “Good” CLI tool ? How to

    start to create “Good” CLI tool ? https://www.flickr.com/photos/36247316@N00/3108399560
  16. #1 ͭͷ͜ͱʹूத͍ͯ͠Δ ௚ײతʹ࢖͑Δ ଞͷπʔϧͱ࿈ܞͰ͖Δ ར༻Λॿ͚ͯ͘ΕΔ ద੾ͳσϑΥϧτ஋Λ࣋ͪઃఆ΋Ͱ͖Δ ۤ௧ͳ͘ΠϯετʔϧͰ͖Δ ͙͢ʹվमͰ͖Δ #2 #3

    #4 #5 #6 #7 https://www.flickr.com/photos/36247316@N00/3108399560
  17. Good CLI Tool #1 Keep It Simple, Stupid ! ͭͷ͜ͱʹूத͍ͯ͠Δ

    https://www.flickr.com/photos/110382334@N05/11302995614
  18. https://www.flickr.com/photos/110382334@N05/11302995614

  19. খ͍͞΋ͷ͸ඒ͍͠ 4NBMMJTCFBVUJGVM ͭͷϓϩάϥϜʹ͸ ͭͷ͜ͱΛ͏·͘΍ΒͤΔ .BLFFBDIQSPHSBNEPPOFUIJOHXFMM https://www.flickr.com/photos/110382334@N05/11302995614

  20. https://www.flickr.com/photos/110382334@N05/11302995614 ̎ͭҎ্ͷ͜ͱΛ΍Ζ͏ͱ ͢Δ͚ͩͰෳࡶ౓͸૿͢ ཧղͰ͖ͳ͍ɾशಘͰ͖ͳ͍ ϝϯςφϯεͰ͖ͳ͍

  21. Good CLI Tool #2 Intuitive UI/UX ௚ײతʹ࢖͑Δ https://www.flickr.com/photos/hindrik/5568789280

  22. $-*πʔϧʹ΋6*69 $-*πʔϧͷྺ࢙͸௕͍ ׳श͕ଘࡏ͢Δ https://www.flickr.com/photos/hindrik/5568789280

  23. Command Pattern https://www.flickr.com/photos/hindrik/5568789280

  24. > grep —i -C 4 "some string" /tmp https://www.flickr.com/photos/hindrik/5568789280

  25. > grep —i -C 4 "some string" /tmp &YFDVUBCMF https://www.flickr.com/photos/hindrik/5568789280

  26. > grep —i -C 4 "some string" /tmp &YFDVUBCMF 0QUJPOT

    https://www.flickr.com/photos/hindrik/5568789280
  27. > grep —i -C 4 "some string" /tmp &YFDVUBCMF 0QUJPOT

    "SHVNFOUT https://www.flickr.com/photos/hindrik/5568789280
  28. > git --no-pager push -v origin master https://www.flickr.com/photos/hindrik/5568789280

  29. > git --no-pager push -v origin master &YFDVUBCMF https://www.flickr.com/photos/hindrik/5568789280

  30. > git --no-pager push -v origin master &YFDVUBCMF $PNNBOE https://www.flickr.com/photos/hindrik/5568789280

  31. > git --no-pager push -v origin master &YFDVUBCMF (MPCBM 0QUJPOT

    $PNNBOE https://www.flickr.com/photos/hindrik/5568789280
  32. > git --no-pager push -v origin master &YFDVUBCMF (MPCBM 0QUJPOT

    $PNNBOE $PNNBOE 0QUJPOT https://www.flickr.com/photos/hindrik/5568789280
  33. > git --no-pager push -v origin master &YFDVUBCMF (MPCBM 0QUJPOT

    $PNNBOE $PNNBOE 0QUJPOT "SHVNFOUT https://www.flickr.com/photos/hindrik/5568789280
  34. Option Pattern https://www.flickr.com/photos/hindrik/5568789280

  35. > grep —i -C 4 "some string" /tmp https://www.flickr.com/photos/hindrik/5568789280

  36. > grep —i -C 4 "some string" /tmp 4XJUDI Ҿ਺Λ൐Θͳ͍

    https://www.flickr.com/photos/hindrik/5568789280
  37. > grep —i -C 4 "some string" /tmp 4XJUDI Ҿ਺Λ൐Θͳ͍

    'MBH Ҿ਺Λ൐͏ https://www.flickr.com/photos/hindrik/5568789280
  38. > grep —i > grep --ignore-case https://www.flickr.com/photos/hindrik/5568789280

  39. > grep —i > grep --ignore-case 4IPSU ߴ଎ʹ࢖͏ͨΊʹ https://www.flickr.com/photos/hindrik/5568789280

  40. > grep —i > grep --ignore-case 4IPSU -POH ߴ଎ʹ࢖͏ͨΊʹ ՄಡੑΛߴΊΔ

    https://www.flickr.com/photos/hindrik/5568789280
  41. (/6ඪ४ΠϯλʔϑΣʔε cf. https://www.gnu.org/prep/standards/html_node/ Command_002dLine-Interfaces.html https://www.flickr.com/photos/hindrik/5568789280

  42. https://www.flickr.com/photos/hindrik/5568789280 My Interface design

  43. https://www.flickr.com/photos/hindrik/5568789280 ࠷΋΍Γ͍ͨ͜ͱΛ࠷΋؆୯ʹ Φϓγϣϯ͕ඞཁͳΒShortΦϓγϣϯΛ४උ͢Δ σϑΥϧτͰഁյతૢ࡞Λ͠ͳ͍ ର࿩ΠϯλʔϑΣʔεΛආ͚Δ LongΦϓγϣϯΛ४උ͢Δ e.g., —force ࣗಈԽͷ๦͛ʹͳΔ

  44. Good CLI Tool #3 Play well with others ଞͷπʔϧͱ࿈ܞͰ͖Δ https://www.flickr.com/photos/alexsk/3251194325

  45. $-*πʔϧ͸ଞͷεΫϦϓτ ͔Βݺͼग़͞ΕΔ 4IFMMTDSJQU΍$SPO $IFG %PDLFSpMF https://www.flickr.com/photos/alexsk/3251194325

  46. Exit Code https://www.flickr.com/photos/alexsk/3251194325

  47. exit 0 exit 1 nonzero ੒ޭ ࣦഊ https://www.flickr.com/photos/alexsk/3251194325

  48. Output Stream https://www.flickr.com/photos/alexsk/3251194325

  49. stdout stderr Τϥʔϝοηʔδ ϑΝΠϧʹॻ͖ग़͍ͨ͠ ύΠϓͰ౉͍ͨ͠ https://www.flickr.com/photos/alexsk/3251194325 ඪ४Τϥʔ ඪ४

  50. Good CLI Tool #4 Documentation ར༻Λॿ͚ͯ͘ΕΔ https://www.flickr.com/photos/jjpacres/3293117576

  51. υΩϡϝϯτ΍6TBHF͕ ଘࡏ͠ͳ͍πʔϧͳͲ ୭΋࢖͍ͨ͘ͳ͍ ར༻౓ʹ߹ΘͤͨυΩϡϝϯτΛ४උ͢Δ https://www.flickr.com/photos/jjpacres/3293117576

  52. Document Pattern https://www.flickr.com/photos/jjpacres/3293117576

  53. ར༻ස౓ https://www.flickr.com/photos/jjpacres/3293117576

  54. ར༻ස౓ 3&"%.&NE ࢖͏͔൱͔Λ൑அ͢Δ https://www.flickr.com/photos/jjpacres/3293117576

  55. ར༻ස౓ 3&"%.&NE 6TBHF ࢖͏͔൱͔Λ൑அ͢Δ πʔϧΛಈ͔ͨ͢Ίʹ ࠷௿ݶ஌Δ΂͖ ࢖͍ํΛཧղ͢Δ IFMQI https://www.flickr.com/photos/jjpacres/3293117576

  56. ར༻ස౓ 3&"%.&NE 6TBHF .BO ࢖͏͔൱͔Λ൑அ͢Δ πʔϧΛಈ͔ͨ͢Ίʹ ࠷௿ݶ஌Δ΂͖ ࢖͍ํΛཧղ͢Δ ෳࡶͳྫ΍ ΑΓॊೈʹ࢖͏ͨΊ

    ͷΦϓγϣϯΛൃݟ͢Δ IFMQI https://www.flickr.com/photos/jjpacres/3293117576
  57. Good CLI Tool #5 Configurable ద੾ͳσϑΥϧτ஋Λ࣋ͪ ઃఆ΋Ͱ͖Δ https://www.flickr.com/photos/dwilkin/12153072866

  58. ϢʔβʹແବͳೖྗΛ ͤ͞ͳ͍ https://www.flickr.com/photos/dwilkin/12153072866

  59. ϢʔβʹແବͳೖྗΛ ͤ͞ͳ͍ ͕ ޷͖ʹઃఆ΋Ͱ͖Δ https://www.flickr.com/photos/dwilkin/12153072866 શһΛຬ଍ͤ͞Δ͜ͱ͸Ͱ͖ͳ͍

  60. Configuration Pattern https://www.flickr.com/photos/dwilkin/12153072866

  61. ༏ઌ౓ https://www.flickr.com/photos/dwilkin/12153072866

  62. ༏ઌ౓ σϑΥϧτ஋ https://www.flickr.com/photos/dwilkin/12153072866

  63. ༏ઌ౓ σϑΥϧτ஋ ઃఆϑΝΠϧ ਓ͕ؒಡΊΔ΋ͷ(json/YAML/DSL/HCL) https://www.flickr.com/photos/dwilkin/12153072866

  64. ༏ઌ౓ σϑΥϧτ஋ ઃఆϑΝΠϧ ؀ڥม਺ ਓ͕ؒಡΊΔ΋ͷ(json/YAML/DSL/HCL) https://www.flickr.com/photos/dwilkin/12153072866

  65. ༏ઌ౓ σϑΥϧτ஋ ઃఆϑΝΠϧ ؀ڥม਺ ΦϓγϣϯҾ਺ ਓ͕ؒಡΊΔ΋ͷ(json/YAML/DSL/HCL) https://www.flickr.com/photos/dwilkin/12153072866

  66. Good CLI Tool #6 Painless Installation ۤ௧ͳ͘ΠϯετʔϧͰ͖Δ https://www.flickr.com/photos/midorisyu/752223850

  67. ର৅Ϣʔβʹ߹ͬͨ Πϯετʔϧํ๏ .BDϢʔβʹ͸ʁ1FSMϢʔβʹ͸ʁ https://www.flickr.com/photos/midorisyu/752223850

  68. 1 Command Install https://www.flickr.com/photos/midorisyu/752223850

  69. > brew install > apt-get install > yum install >

    cpan > gem install > pip install https://www.flickr.com/photos/midorisyu/752223850
  70. Good CLI Tool #7 maintainable ͙͢ʹվमͰ͖Δ https://www.flickr.com/photos/damski/7045068945

  71. Τϥʔ͸ඞͣىΔ ى͖ͨͱ͖ʹԿ͕ىͬͯΔ͔ ৄࡉ͕֬ೝͰ͖Δ ιʔεΛݟͣʹԿ͕ىͬͯΔ͔Θ͔Δ ιʔεͷͲ͜Λ௚ͤ͹Α͍͔Θ͔Δ https://www.flickr.com/photos/damski/7045068945

  72. DEBUG Option https://www.flickr.com/photos/damski/7045068945

  73. > tool --debug Φϓγϣϯ https://www.flickr.com/photos/damski/7045068945

  74. > tool --debug > export DEBUG=1 > tool Φϓγϣϯ ؀ڥม਺

    ։ൃऀ޲͚ https://www.flickr.com/photos/damski/7045068945
  75. #1 ͭͷ͜ͱʹूத͍ͯ͠Δ ௚ײతʹ࢖͑Δ ଞͷπʔϧͱ࿈ܞͰ͖Δ ར༻Λॿ͚ͯ͘ΕΔ ద੾ͳσϑΥϧτ஋Λ࣋ͪઃఆ΋Ͱ͖Δ ۤ௧ͳ͘ΠϯετʔϧͰ͖Δ ͙͢ʹվमͰ͖Δ #2 #3

    #4 #5 #6 #7 https://www.flickr.com/photos/36247316@N00/3108399560
  76. lྑ͍z$-* ͍͔ʹlྑ͍z$-*πʔϧΛ࡞Γ࢝ΊΔ͔ʁ What How to start to create “Good” CLI

    tool ? https://www.flickr.com/photos/36247316@N00/3108399560
  77. #1 ͲΜͳπʔϧΛ࡞Δ͔ߟ͑Δ ݴޠΛબͿ 3&"%.&NEΛॻ͘ #2 #3 https://www.flickr.com/photos/36247316@N00/3108399560 ߴ଎ʹϓϩτλΠϓΛͭ͘Δ %&.0 #4

  78. How to start #1 Chance ͲΜͳπʔϧΛ࡞Δ͔ߟ͑Δ https://www.flickr.com/photos/cleopold73/3677296594

  79. $-*πʔϧͷ ॳظিಈ ෳࡶͳ࡞ۀΛࣗಈԽ͍ͨ͠ ͋ΔλεΫͷੜ࢈ੑΛߴΊ͍ͨ "1*ͷ$-*ΫϥΠΞϯτཉ͍͠ ʜ https://www.flickr.com/photos/cleopold73/3677296594

  80. ͍͖ͳΓෳࡶͳ͜ͱΛ͠ͳ͍ ! ͭͷ͜ͱʹूத͢Δ Good CLI Tool #1 https://www.flickr.com/photos/cleopold73/3677296594

  81. ໰୊ͷҰ෦Λղܾ͢Δ͚ͩͰΑ͍ ! ଞͷπʔϧͱ࿈ܞͰ͖Δ Α͏ʹ͢Δ Good CLI Tool #3 https://www.flickr.com/photos/cleopold73/3677296594

  82. How to start #2 Programming language ݴޠΛબͿ https://www.flickr.com/photos/8153468@N04/2668229310

  83. ݴޠબ୒͸ πʔϧͷ഑෍ํ๏ʹ௚݁͢Δ ! ۤ௧ͳ͘Πϯετʔϧ ͯ͠΋Β͏͜ͱΛߟ͑Δ Good CLI Tool #6 https://www.flickr.com/photos/8153468@N04/2668229310

  84. (P ͋ΒΏΔϓϥοτϑΥʔϜ ͷϢʔβΛର৅ʹ 1FSM Perl mongerΛର৅ʹ SVCZ rubyistΛର৅ʹ https://www.flickr.com/photos/8153468@N04/2668229310 ˠόΠφϦμ΢ϯϩʔυͰ

    ˠHFNͰ ˠDQBOͰ
  85. How to start #3 README Driven Development 3&"%.&NEΛॻ͘ https://www.flickr.com/photos/alessiorr/14144160337

  86. README Driven Development https://www.flickr.com/photos/alessiorr/14144160337

  87. ίʔυΛॻ͘લʹ 3&"%.&NEΛॻ͘ ໊લΛߟ͑Δɼ $-*πʔϧ͕ԿΛ͢Δ΋ͷͳͷ͔Λߟ͑Δɼ $-*πʔϧͷΠϯλʔϑΣʔε ࢖͍ํ Λߟ͑Δ https://www.flickr.com/photos/alessiorr/14144160337

  88. ࣗ෼͕ԿΛ࡞Γ͍ͨͷ͔ ੔ཧ্ͨ͠Ͱ࡞Γ࢝ΊΒΕΔ https://www.flickr.com/photos/alessiorr/14144160337

  89. None
  90. Ϣʔβࢹ఺ͰσβΠϯͰ͖Δ https://www.flickr.com/photos/alessiorr/14144160337

  91. ൪ςϯγϣϯ͕ߴ͍ͱ͖ʹ υΩϡϝϯτ͕ॻ͚Δ ࡞ΓऴΘͬͨޙʹυΩϡϝϯτΛ੔උ͢Δ ͷ͸͠ΜͲ͍ʜ https://www.flickr.com/photos/alessiorr/14144160337

  92. NAME ==== ! ## Description ! ## Usage ! ##

    VS. https://www.flickr.com/photos/alessiorr/14144160337
  93. ස౓͕ߴ͍ͳΒͰ͖Δ͚ͩ ୹໊͍લΛ෇͚Δ ස౓͕௿͍ͳΒ આ໌తͳ໊લΛ෇͚Δ = ίϚϯυ໊ NAME ==== ! ##

    Description ! ## Usage ! ## VS. ໊લ https://www.flickr.com/photos/alessiorr/14144160337
  94. ͜Ε͸ͲΜͳπʔϧͳͷ͔ʁ ͭͷ͜ͱʹूத͍ͯ͠Δ Good CLI Tool #1 = ୹͘؆ܿͳઆ໌͕ॻ͚Δ NAME ====

    ! ## Description ! ## Usage ! ## VS. આ໌ https://www.flickr.com/photos/alessiorr/14144160337
  95. ΠϯλʔϑΣʔεͷఆٛ ௚ײతʹ࢖͑Δ Good CLI Tool #2 Ϣʔβͷࢹ఺Ͱ ࠷΋΍Β͍ͤͨ͜ͱΛ ࠷΋؆୯ʹͰ͖ΔΑ͏ʹ NAME

    ==== ! ## Description ! ## Usage ! ## VS. ࢖͍ํ https://www.flickr.com/photos/alessiorr/14144160337
  96. ൺֱ ଞͷπʔϧͱͷൺֱ NAME ==== ! ## Description ! ## Usage

    ! ## VS. ࣅͨΑ͏ͳπʔϧ͸ଘࡏ͢Δ શ͘ಉ͡΋ͷΛ࡞ͬͯ΋ ҙຯͳ͍ ࣅͨπʔϧͱൺ΂ͯ! Կ͕༏Ε͍ͯΔͷ͔Λߟ͑Δ! → πʔϧͷಛ௃ʹͳΔ https://www.flickr.com/photos/alessiorr/14144160337
  97. όοδ όοδͷ४උ = CI as a Service ͷઃఆ = ͸͡Ί͔Βςετ؀ڥΛ!

    ४උ͢Δ ςετ݁ՌΛϢʔβʹ ݟͤଓ͚Δ͜ͱͰ ςετΛॻ͘Ϟνϕʔγϣϯ Λอͪଓ͚Δ NAME ==== ! ## Description ! ## Usage ! ## VS. https://www.flickr.com/photos/alessiorr/14144160337
  98. https://www.flickr.com/photos/sergiu_bacioiu/4664215911 How to start #4 ߴ଎ʹϓϩτλΠϓΛ࡞Δ Build a prototype as

    soon as possible
  99. https://www.flickr.com/photos/sergiu_bacioiu/4664215911

  100. https://www.flickr.com/photos/sergiu_bacioiu/4664215911

  101. LIVE https://www.flickr.com/photos/sergiu_bacioiu/4664215911

  102. (PݴޠΛ࢖ͬͯ $-*πʔϧΛ࡞੒ɼ ΫϩείϯύΠϧͯ͠ (JUIVCʹϦϦʔεʂ https://www.flickr.com/photos/sergiu_bacioiu/4664215911

  103. (PݴޠΛ࢖ͬͯ $-*πʔϧΛ࡞੒ɼ ΫϩείϯύΠϧͯ͠ (JUIVCʹϦϦʔεʂ https://www.flickr.com/photos/sergiu_bacioiu/4664215911 tcnksm/cli-init mitchellh/gox tcnksm/ghr codegansta/cli

  104. #1 ͭͷ͜ͱʹूத͍ͯ͠Δ ௚ײతʹ࢖͑Δ ଞͷπʔϧͱ࿈ܞͰ͖Δ ར༻Λॿ͚ͯ͘ΕΔ ద੾ͳσϑΥϧτ஋Λ࣋ͪઃఆ΋Ͱ͖Δ ۤ௧ͳ͘ΠϯετʔϧͰ͖Δ ͙͢ʹվमͰ͖Δ #2 #3

    #4 #5 #6 #7 https://www.flickr.com/photos/36247316@N00/3108399560
  105. #1 ͲΜͳπʔϧΛ࡞Δ͔ߟ͑Δ ݴޠΛબͿ 3&"%.&NEΛॻ͘ #2 #3 https://www.flickr.com/photos/36247316@N00/3108399560 ߴ଎ʹϓϩτλΠϓΛͭ͘Δ %&.0 #4