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

cobra は便利になっている

6ed12627fec46a135f1bce5d56f3568e?s=47 nwiizo
August 04, 2022

cobra は便利になっている

2022年3-shake SRE Tech Talk #4
https://3-shake.connpass.com/event/253028/

6ed12627fec46a135f1bce5d56f3568e?s=128

nwiizo

August 04, 2022
Tweet

More Decks by nwiizo

Other Decks in Technology

Transcript

  1. TIBLF43&5FDI5BML!OXJJ[P DPCSB͸ศརʹͳ͍ͬͯΔ TQGDPCSB࠷৽ػೳٴͼӡ༻࣌ʹޮ͘ػೳ

  2. ૣ଎Ͱ͕͢ օ͞ΜɺࣗಈԽ 
 ͯ͠·͔͢ʁ ୀ۶ͳ͜ͱ͸1ZUIPOʹ΍ΒͤΑ͏ୈ൛ʕϊϯϓϩάϥϚʔʹ΋Ͱ͖ΔࣗಈԽॲཧϓϩάϥϛϯά

  3. ๻΋ࣗಈԽ͕޷͖Ͱ͢

  4. ͔͠͠ɺෳࡶʹൃୡͨ͠ 
 ࣗಈԽ͸ࣗવͷౖΓͱ 
 ۠ผ͕͔ͭͳ͍

  5. ࣗಈԽʹඞཁͳͷ͸டং

  6. ίϚϯυϥΠϯπʔϧʹ͍ͭͯޠΔͱ͖ʹ๻ͷޠΔ͜ͱ #yapcasia
 https://speakerdeck.com/tcnksm/komandorainturunituiteyu-rutokinipu-falseyu-rukoto-number-yapcasia $-*5PPMΛॻ͘ͱ͖ϨϏϡʔͰ໎ͬͨ࣌ʹ͸ 
 ΄΅ɺඞͣͪ͜ΒͷυΩϡϝϯτΛݟ͍ͯ·͢ɻ 
 πʔϧͷػೳΑΓͪ͜ΒʹཔΕʂʂʂ

  7. ίϚϯυϥΠϯπʔϧʹ͍ͭͯޠΔͱ͖ʹ๻ͷޠΔ͜ͱΑΓҾ༻ w ίϚϯυϥΠϯπʔϧʹ͓͍ͯॏཁͳϙΠϯτ 
 ͭͷ͜ͱʹूத͍ͯ͠ 
 ௚ײతʹ࢖͑Δ 
 ଞͷπʔϧͱ࿈ܞͰ͖Δ 


    ར༻Λॿ͚ͯ͘ΕΔ 
 ద੾ͳσϑΥϧτ஋Λ࣋ͪઃఆ΋Ͱ͖Δ 
 ۤ௧ͳ͘ΠϯετʔϧͰ͖Δ 
 ͙͢ʹվमͰ͖Δ  ίϚϯυϥΠϯπʔϧʹ͍ͭͯޠΔͱ͖ʹ๻ͷޠΔ͜ͱ #yapcasia
 https://speakerdeck.com/tcnksm/komandorainturunituiteyu-rutokinipu-falseyu-rukoto-number-yapcasia w ͍͔ʹzྑ͍z$-*πʔϧΛ࡞Γ࢝ΊΔ͔ʁʹ͍ͭͯͷͭͷखॱ 
 ͲΜͳπʔϧΛ࡞Δ͔ߟ͑Δ 
 ݴޠΛબͿ 
 3&"%/&NEΛॻ͘ 
 ߴ଎ʹϓϩτλΠϓΛ࡞Δ
  8. ࢲͷࠢͷ੤໿📄 w 4IFMM4DSJQU͸ߦ͙Β͍·Ͱ w ͦΕҎ֎͸(PMBOHͰ։ൃ 
 🔔ϥΠϒϥϦ΍πʔϧ͕ͳ͍ͳͲͰͦͷબ୒ࢶҎ֎ͩͱ 
 ɹࣗಈԽʹͱͯ΋޻਺͕͔͔Δ৔߹ʹ͸ଞͷݴޠΛ࢖͏ 


    🔔(PݴޠͰͷϝϦοτ͸͍͔ͭ͋͘Γ·͕͢zۤ௧ͳ͘ΠϯετʔϧͰ͖ͯར༻͠ଓ͚қ͍z 
 ɹίϚϯυϥΠϯπʔϧΛॻ͘͜ͱʹ޲͍͍ͯΔͱࢥ͍·͕͢ຊൃදͰ͸औΓѻΘͳ͍ 
 🔔Α͍(PͷίʔυΛॻ͘ʹ͸ʮ(Pʹೖͬͯ͸(Pʹै͑ʯͳͲͷΑ͍ࢿྉ͕͋ΔͷͰ 
 ɹຊൃදͰ͸औΓѻΘͳ͍ͷͰͥͻɺಡΜͰΈͯ΄͍͠Ͱ͢ɻ 
 ɹ
  9. ͷ ࿩ʹ΍ͬͱಥೖ͢Δ -5ͳͷʹ લஔ͖Ͱ͋Δ

  10. TQGDPCSBͱ͸ʁ w (PʹΑΔ੩తαΠτδΣωϨʔλʔͰ͋ΔIVHPͷ ։ൃऀͱͯ͠஌ΒΕΔɻTQGࢯʹΑΔ$-*Λ࡞੒ ͢ΔҝͷπʔϧͰ͢ɻ  IUUQTHJUIVCDPNTQGDPCSB $ go mod

    init SRETT04 $ cobra-cli init ਽ܗͷ࡞੒ . ᵓ── LICENSE ᵓ── README.md ᵓ── cmd │ └── root.go ᵓ── go.mod ᵓ── go.sum └── main.go 1 directory, 6 fi les IUUQTTZVNIBUFOBCMPHDPNFOUSZ (PMBOHͰ$-*5PPMΛ࡞Δ࣌ʹ͸$PCSBΛ࢖͍͕ͪ DPCSB͔ΒDPCSBDMJʹมߋ͠·ͨ͠ IUUQTHJUIVCDPNTQGDPCSBSFMFBTFTUBHW
  11. TQGDPCSBͱ͸ʁ w ༷ʑͳػೳ͕͋Γ$PCSBΛར༻͢Δͱ 
 αϒίϚϯυͷݟ௨͠ͳͲ΋ྑ͘ͳΓ 
 ·ͨɺIFMQ΁ͷ௥Ճ΋ࣗಈͰߦͬͯ͘ΕΔ  IUUQTHJUIVCDPNTQGDPCSB $

    cobra-cli add get $ cobra-cli add create αϒίϚϯυͷ௥Ճ . ᵓ── LICENSE ᵓ── README.md ᵓ── cmd │ ᵓ── create.go │ ᵓ── get.go │ └── root.go ᵓ── go.mod ᵓ── go.sum └── main.go ϑϥάͷ௥ՃͳͲ͸ࣗલͰ࣮૷͕ඞཁ 
 JOJU ಺ͰϑϥάΛఆٛ ࣮ࡍͷॲཧͰϑϥάΛࢀর HFUHP΍DSFBUFHPʹ 
 ֤ػೳΛ࣮૷Λ͢Ε͹ྑ͍ 🔔-POH)FMQʹ 
 ɹ(JUIVC3FQPTJUPSZ͸ 
 ɹॻ͍͓͍ͯͯ΄͍͠ 
 ɹະདྷͷӡ༻Λ͢Δ୭͔ͷͨΊʹ IUUQTHJUIVCDPNTQGDPCSBCMPCNBJOVTFS@HVJEFNE
  12. ͷศརػೳͷ ࿩ʹ΍ͬͱಥೖ͢Δ -5ͳͷʹ ຊ୊Ͱ͋Δ

  13. ᶃࣗಈิ׬  IUUQTTZVNIBUFOBCMPHDPNFOUSZ (Pݴޠͷ$-*࡞੒πʔϧͰ͋ΔDPCSBͷγΣϧิ׬ͷੜ੒͕͋·Γʹ΋؆୯ $ [command] completion fi sh fi

    TIิ׬ϑΝΠϧ $ [command] completion [bash|zsh| fi sh|powershell] CBTIc[TIc fi TIc QPXFSTIFMM 
 ิ׬ϑΝΠϧ ࣗಈิ׬ϑΝΠϧ͕؆୯ʹੜ੒Ͱ͖ΔΑ͏ʹͳΓ·ͨ͠ 
 ରԠ͍ͯ͠Δͷ͸CBTIc[TIcGJTIcQPXFSTIFMMʹରԠ͍ͯ͠Δ
  14. ᶄ(SPVQGMBHTػೳʹ͍ͭͯ w 'MBHΛ૬ޓʹඞཁͳΦϓγϣϯΛද͢৔߹  rootCmd.Flags().StringVarP(&u, "username", "u", "", "Username (required

    if password is set)") rootCmd.Flags().StringVarP(&pw, "password", "p", "", "Password (required if username is set)") rootCmd.MarkFlagsRequiredTogether("username", "password") IUUQTHJUIVCDPNTQGDPCSBCMPCNBJOVTFS@HVJEFNE fl BHHSPVQT Flag Groups rootCmd.Flags().BoolVar(&u, "json", false, "Output in JSON") rootCmd.Flags().BoolVar(&pw, "yaml", false, "Output in YAML") rootCmd.MarkFlagsMutuallyExclusive("json", "yaml") w 'MBHΛ૬ޓʹഉଞతͳΦϓγϣϯΛද͢৔߹ 'MBHʹάϧʔϓػೳ௥Ճ͢Δͷ΋؆୯ʹ࣮ݱͰ͖Δ ⭐ӡ༻࣌ʹґཔ͢Δ࣌ʹָ 
 ɹԿ͕଍Γͳ͍͔ࣔ͢ͷେมʜ
  15. ᶅΞΫςΟϒϔϧϓ w #BTIͱ[TIͷΈʹରԠ͍ͯ͠ΔɻUBCΛԡ͍ͯ͠ΔλΠϛϯάͰ 
 ର࿩తʹϔϧϓΛग़͢ػೳ  IUUQTHJUIVCDPNTQGDPCSBCMPCNBJOBDUJWF@IFMQNE ValidArgsFunction: func(cmd *cobra.Command,

    args []string, toComplete string) ([]string, cobra.ShellCompDirective) { var comps []string if len(args) == 0 { comps = cobra.AppendActiveHelp(comps, "You must choose a name for the repo you are adding") } else if len(args) == 1 { comps = cobra.AppendActiveHelp(comps, "You must specify the URL for the repo you are adding") } else { comps = cobra.AppendActiveHelp(comps, "This command does not take any more arguments") } return comps, cobra.ShellCompDirectiveNoFileComp }, bash-5.1$ helm repo add [tab] You must choose a name for the repo you are adding bash-5.1$ helm repo add grafana [tab] You must specify the URL for the repo you are adding bash-5.1$ helm repo add grafana https://grafana.github.io/helm-charts [tab] This command does not take any more arguments ⭐ର࿩࣌ʹָʹͳΔͷͰخ͍͠ɹ fi TIར༻ऀ͸Ըܙʹ༬͔Εࢮ
  16. ׬