Mais conteúdo relacionado Semelhante a Chef meetup vol2_higanwoks (20) Mais de Yukihiko SAWANOBORI (16) Chef meetup vol2_higanwoks2. 紹介
• HiganWorks 合同会社
プラットホームエンジニア / 代表社員
• インフラ関係自動化
• クラウド的なもの(彼岸)で色々やる
• Avatarはこんな感じ
2
•sawanoboly@github
•sawanoboly@twitter
•yukihiko.sawanobori@facebook
Monday, May 20, 13
9. Knife Pluginのコツ1/3
• サブコマンド
• クラス名=分解されてサブコマンドに
• class NodeEdit #=> `knife node edit`
• Knifeを継承して好きなクラスを作ればOK
• banner #=> helpの表示内容
9
Monday, May 20, 13
10. Knife Pluginのコツ2/3
• オプション
• コマンドラインオプション
• knife.rb に書く
`knife[:optionname] = hogehoge `
• Knifeを継承したクラスに#optionでOK
10
option
:twitter_consumer_key,
:short
=>
"-‐K
CONSUMER_KEY",
:long
=>
"-‐-‐twitter_consumer_key",
:description
=>
"Your
Twitter
Consumer
Key",
:proc
=>
Proc.new
{
|key|
Chef::Config[:knife][:twitter_consumer_key]
=
key
}
Monday, May 20, 13
11. Knife Pluginのコツ3/3
• UI
• 標準でHighLine(gem)が使われている
• ANSIカラーシーケンス
• HignLine#listで簡単リスト表示
全体的に結構レガシーな感じ...
11
Monday, May 20, 13
14. Post(1)
14
class
Chef
class
Knife
class
TwitterPost
<
Knife
include
TwitterBase
banner
"knife
twitter
post
(options)"
def
run
t_configure
begin
Twitter.update(locate_config_value(:twitter_message))
ui.info("Tweet
Success!
#=>
#{locate_config_value(:twitter_message)}")
knife twitter post
の素
#run に実行内容
#ui でコンソールに表示
Monday, May 20, 13
15. Post(2)
15
option
:twitter_message,
:short
=>
"-‐m
TWEET_MEAASAGE",
:long
=>
"-‐-‐twitter_message",
:description
=>
"Your
Tweet",
:proc
=>
Proc.new
{
|message|
Chef::Config[:knife]
[:twitter_message]
=
message
},
:default
=>
"Tweet
with
knife-‐twitter
"
+
::Knife::Twitter::VERSION
+
"
"
+
Time.now.to_s
CLオプションの
引数指定
省略時のdefault
Monday, May 20, 13
16. TimeLine(1)
16
banner
"knife
twitter
tl
(options)"
def
run
t_configure
begin
if
locate_config_value(:twitter_mentions)
timeline
=
Twitter.mentions_timeline
else
timeline
=
Twitter.home_timeline
end
timelineを取得
Monday, May 20, 13
17. TimeLine(2)
17
tl_list
=
[]
timeline.map
do
|tl|
tl_list
<<
ui.color(tl[:user][:screen_name],
:cyan)
tl_list
<<
ui.color(tl[:created_at].to_s,
:magenta)
tl_list
<<
ui.color(tl[:text])
end
puts
ui.list(tl_list,
:uneven_columns_across,
3)
HighLineで色つけ、tl_listへ
tl_listの中身を3カラムで適当に表示
Monday, May 20, 13