Upgrade to Pro — share decks privately, control downloads, hide ads and more …

spf13/cobraでもできる簡単CLIツール / Fukuoka.go #11

spf13/cobraでもできる簡単CLIツール / Fukuoka.go #11

Fukuoka.go #11 LT

69b93af68320a590f607c296e8edff73?s=128

Ken’ichiro Oyama

June 14, 2018
Tweet

Transcript

  1. খࢁ݈Ұ࿠(.01FQBCP *OD 'VLVPLBHP TQGDPCSBͰ΋Ͱ͖Δ ؆୯$-*πʔϧ  

  2. γχΞΤϯδχΞ খࢁ݈Ұ࿠!L-P8 ϗεςΟϯάࣄۀ෦ϗεςΟϯάάϧʔϓϚωʔδυΫϥ΢υνʔϜ IUUQTHJUIVCDPNL-P8  

  3. .Z$-*UPPMT w BXTQFD w LPNB w PDUPQVCMJTI w PDUPQBDLBHF w

    DFSUNBO w TDPOC w UNQGL w SFDJQF w CVO w LVNPNF w CBDLMPHDQ w EFWMPDBM  
  4. .Z$-*UPPMT w BXTQFD w LPNB w PDUPQVCMJTI w PDUPQBDLBHF w

    DFSUNBO w TDPOC w UNQGL w SFDJQF w CVO w LVNPNF w CBDLMPHDQ w EFWMPDBM   PQUQBSTF $BLF4IFMM /PEF #BTI
  5. *5IPS  

  6. 5IPS w5IPSJTBUPPMLJUGPSCVJMEJOHQPXFSGVMDPNNBOEMJOFJOUFSGBDFT *UJTVTFEJO#VOEMFS 7BHSBOU 3BJMTBOEPUIFST wIUUQXIBUJTUIPSDPN w3VCZ੡ͷϑϧελοΫͳ$-*ϥΠϒϥϦ wҾ਺΍Φϓγϣϯͷ૊Έָཱ͕ͯͰػೳͷ࣮૷ʹूதͰ͖Δ wศརʹ࡞ΒΕ͍͗ͯͯ͢ɺ΋͸΍3VCZΛॻ͍͍ͯΔͱ͍͏ΑΓ5IPS Λॻ͍͍ͯΔ

     
  7. ͱ͜ΖͰ࠷ۙ(PΛ֮͑·ͨ͠  

  8. .Z$-*UPPMT XSJUUFOJO(P  

  9. DHSQT wDHSQTJTBTFUPGDPNNBOETGPSDIFDLJOHDHSPVQT wIUUQTHJUIVCDPNL-P8DHSQT wେྔͷDHSPVQ͕࡞੒͞ΕΔ؀ڥͰɺQFDPͳͲͱ࿈ܞͯ͠ޮ཰తʹ DHSPVQ৘ใΛऔΓѻ͏ͨΊͷίϚϯυ   > cgrps stat

    $(cgrps ls | peco) > ps u --pid $(cgrps ls | peco | cgrps pids | xargs)
  10.  

  11. UCMT wUCMTJTB$*'SJFOEMZUPPMGPSEPDVNFOUBEBUBCBTF XSJUUFOJO(P wIUUQTHJUIVCDPNL-P8UCMT w.BSLEPXO ('. ܗࣜͰσʔλϕʔευΩϡϝϯτΛੜ੒ͯ͘͠ΕΔί Ϛϯυ w$*ʹ૊ΈࠐΜͰυΩϡϝϯτͷߋ৽ΛνΣοΫ͢ΔίϚϯυ΋͋Δ 

     > tbls doc postgres://user:pass@hostname:5432/dbname ./dbdoc
  12. None
  13. (PͰ$-*πʔϧΛ࡞Δ  

  14. (PͰ$-*πʔϧΛ࡞Δ w$-*ϥΠϒϥϦʢϑϨʔϜϫʔΫʣΛ࢖͏ wͨͩϥΠϒϥϦΛ࢖͏ͷͰ͸ͳ͘δΣωϨʔτπʔϧΛ࢖ͬͯߴ଎ʹ ϓϩτλΠϓΛ࡞Δ   UDOLTNHDMJ VSGBWFDMJ NJUDIFMMIDMJ HPDNE

    &YBNQMF IUUQTTQFBLFSEFDLDPNUDOLTNLPNBOEPSBJOUVSVOJUVJUFZVSVUPLJOJQVGBMTFZVSVLPUPOVNCFSZBQDBTJB TMJEF
  15. TQGDPCSB  

  16.   Cobra is both a library for creating powerful

    modern CLI applications as well as a program to generate applications and command files.
  17. TQGDPCSB w,VCFOFUFT΍.PCZ %PDLFS ɺ0QFO4IJGUͳͲͰ࢖ΘΕ͍ͯΔ $-*ϥΠϒϥϦʢϑϨʔϜϫʔΫʣͰ͋ΓδΣωϨʔτπʔϧ wDPCSBͷ਽ܗΛDPCSBΛ࢖ͬͯߴ଎ʹϓϩτλΠϓΛ࡞Δ   TQGDPCSB TQGDPCSB

  18. None
  19. Πϯετʔϧ͔ΒίϚϯυ࡞੒ͷྫ  

  20.   /> go get github.com/spf13/cobra/cobra /> cobra init github.com/k1LoW/fukgo

    /> cd $GOPATH/src/github.com/k1LoW/fukgo fukgo/> cobra add hello fukgo/> go build fukgo/> ./cobra 1 2 3 4 5 6
  21.  

  22. ؆୯  

  23. DPCSBίϚϯυ wDPCSBJOJUTQGDPCSB΍TQGWJQFSΛ࢖ͬͨ$-*πʔϧͷ਽ܗΛ ࡞੒͢ΔίϚϯυ wTQGWJQFSʜDPOpHϑΝΠϧΛಡΈࠐΉͨΊͷػߏΛఏڙ͢Δϥ ΠϒϥϦʢඞཁͳ͍৔߹͸ŠWJQFSGBMTFʣ wDPCSBBEEαϒίϚϯυͷ਽ܗΛ௥Ճ࡞੒͢ΔίϚϯυ  

  24. ੜ੒͞Εͨιʔεͷߏ੒ GVLHP ᵓᴷᴷ-*$&/4& ᵓᴷᴷDNE ᴹᵓᴷᴷIFMMPHPʜGVLHPIFMMPίϚϯυͷίʔυ ᴹᵋᴷᴷSPPUHPʜGVLHPίϚϯυͷίʔυ ᵋᴷᴷNBJOHP  

  25. ίʔυͷઆ໌͸ׂѪ ͨͿΜݟͨΒ͙͢Θ͔Δ ͘Β͍ʹ͸Θ͔Γ΍͍͢  

  26. TQGDPCSBͰͰ͖Δ͜ͱ wίϚϯυ͚ͩͷελΠϧ΋αϒίϚϯυΛ࣋ͭελΠϧ΋࣮૷Մೳ wUIPSHFNͰ͸αϒίϚϯυͷελΠϧҎ֎ͷ࣮ݱ͕೉͍͠ wTQGDPCSBͷ৔߹͸DNESPPUHPΛҭͯΕ͹ྑ͍ wIFMQίϚϯυͷࣗಈ࡞੒΍Φϓγϣϯͷ؆୯੍ޚͳͲ͸ଞͷ$-*ϥΠ ϒϥϦͱಉ༷ʹՄೳ wTQGWJQFSͱͷ࿈ܞͰઃఆϑΝΠϧͱͷ࿈ܞ΋Մೳ  

  27. ଞͷ$-*ϥΠϒϥϦͰͰ͖Δ͜ͱ͸ Ͱ͖ͦ͏  

  28. Ͳͷ$-*ϥΠϒϥϦͰ΋े෼ʹྑ͍ ޷ΈͰબΜͰ  

  29. *TQGDPCSB  

  30. 5IBOLZPV ࠷৽ͷ࠾༻৘ใΛνΣοΫˠ !QC@SFDSVJU