WindowsでCapfileをUTF-8で書く
Windows で Capfile を UTF-8 で書けたのがうれしかったのでメモ。結論、1行目に coding: utf-8 ってコメント書けばいいだけなんですけどね。なにそれ普通の .rb でも一緒じゃんって話です。
Before coding: utf-8
Capfile
desc "負荷などを表示します."
task "uptime" do
run("uptime")
end
C:\Users\rch850\Desktop>cap -T
C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:93:in `instance_eval': Capfile:1: invalid multibyte char (Windows-31J) (SyntaxError)
Capfile:1: syntax error, unexpected tSTRING_BEG
Capfile:2: syntax error, unexpected tIDENTIFIER, expecting $end
task "uptime" do
^
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:93:in `load'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:89:in `load'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `block in load'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `load'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `block in load_recipes'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `load_recipes'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:31:in `execute!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:14:in `execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/bin/cap:4:in `<top (required)>'
from C:/Ruby193/bin/cap:23:in `load'
from C:/Ruby193/bin/cap:23:in `<main>'
After coding: utf-8
Capfile
# coding: utf-8
desc "負荷などを表示します."
task "uptime" do
run("uptime")
end
C:\Users\rch850\Desktop>cap -T
cap invoke # Invoke a single command on the remote servers.
cap shell # Begin an interactive Capistrano session.
cap uptime # 負荷などを表示します.
Extended help may be available for these tasks.
Type `cap -e taskname' to view it.
なんでこんなことやってんの
desc "負荷などを表示します."
task "uptime" do
run("uptime")
end
C:\Users\rch850\Desktop>cap -T
C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:93:in `instance_eval': Capfile:1: invalid multibyte char (Windows-31J) (SyntaxError)
Capfile:1: syntax error, unexpected tSTRING_BEG
Capfile:2: syntax error, unexpected tIDENTIFIER, expecting $end
task "uptime" do
^
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:93:in `load'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:89:in `load'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `block in load'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `load'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `block in load_recipes'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `load_recipes'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:31:in `execute!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:14:in `execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/bin/cap:4:in `<top (required)>'
from C:/Ruby193/bin/cap:23:in `load'
from C:/Ruby193/bin/cap:23:in `<main>'
# coding: utf-8
desc "負荷などを表示します."
task "uptime" do
run("uptime")
end
C:\Users\rch850\Desktop>cap -T
cap invoke # Invoke a single command on the remote servers.
cap shell # Begin an interactive Capistrano session.
cap uptime # 負荷などを表示します.
Extended help may be available for these tasks.
Type `cap -e taskname' to view it.
なんでこんなことやってんの
Shift_JIS で Capfile 書いていればこんなこと必要ないんですよね。でも Shift_JIS にするのは魂が許さなかったので UTF-8 でこんな風に書いてました。
#
# とりあえず書いてみた Capfile です
#
# coding: utf-8
desc "負荷などを表示します."
task "uptime" do
run("uptime")
end
これだとエラーになっちゃうんですよね。うーん、こりゃ UTF-8 諦めるしかないかなーと思って、desc は英語で書いてました。
でも、コードの引き継ぎとかで「なんで英語なの気取っちゃって」みたいに思われたくないので、なんとか日本語にできないかなーと調べてた所、coding: utf-8 は基本的に1行目に書かなければならないという事が分かりました。はい、ただそれだけです。
結局、一般的な Ruby の話ということで落ち着いたんですが、eval がどうこうってエラーが出てたので Capfile 独自の問題だと勘違いしてて無駄に時間を取られました。
Author And Source
この問題について(WindowsでCapfileをUTF-8で書く), 我々は、より多くの情報をここで見つけました https://qiita.com/rch850/items/752cce5bc8311b5dd83e著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .