便利なPlayコンソールとEclipseでのデバッグ方法Scala+Play 2.0でWebアプリ開発入門(3)(2/3 ページ)

» 2013年01月07日 18時00分 公開
[中村修太,クラスメソッド]

Playコンソールの「履歴コマンド」

 Playコンソール(というか、sbt)では、実行したコマンドの履歴を保存しています。

 矢印の上を押せば、以前に実行したコマンドをさかのぼることが可能です。それ以外にも、下記コマンドを実行すれば、以前実行したコマンドに関する操作ができます。先ほど紹介した8つのコマンドに比べると、使う頻度は少ないと思います。

【1】!

 履歴コマンドのヘルプを表示します。

[gyro] $ !
History commands:
   !!    Execute the last command again
   !:    Show all previous commands
   !:n    Show the last n commands
   !n    Execute the command with index n, as shown by the !: command
   !-n    Execute the nth command before this one
   !string    Execute the most recent command starting with 'string'
   !?string    Execute the most recent command containing 'string'

【2】!!

 直前に実行したコマンドを実行します。

[gyro] $ compile       
[success] Total time: 0 s, completed 2012/12/15 17:03:36
[gyro] $ !! //コンパイルを実行
compile
[success] Total time: 0 s, completed 2012/12/15 17:03:38

【3】!:

 これまで実行した全てのコマンド実行履歴を表示します。

[gyro] $ !:
   0    eclipsify with-source=true
   1    run
   2    test
:
:
   100  !:

【4】!:n

 最後から数えてn個分のコマンドを表示します。

[gyro] $ !:3
   3  !
   4  test
   5  compile

【5】!n

 「!:」コマンドで表示されたインデックスnに対するコマンドを実行します。

[gyro] $ !5 //インデックス5はcompileコマンド
compile
[success] Total time: 0 s, completed 2012/12/15 18:21:48

【6】!-n

 指定したn個前に相当するコマンドを実行します。

[gyro] $ !-6 //6個前に実行した実行したコマンドを再度実行

【7】!string

 'string'から始まる最も近いコマンドを実行します。下記例では「te」から始まる「test」コマンドを実行しています。

[gyro] $ !te    
test
[info] No tests to run for test:test
[success] Total time: 1 s, completed 2012/12/15 18:26:40

【8】!?string

 'string'を含む最も近いコマンドを実行します。下記例では、piを含むcompileコマンドを実行しています。

[gyro] $ !?pi   
compile
[success] Total time: 0 s, completed 2012/12/15 18:27:36

sbtのソースファイル変更の検知機能

 これはsbtの機能ですが、ソースファイルを保存するたびに、自動的にアクションを実行できます。ソースファイルの変更を検知してアクションを実行するためには、アクションの先頭に「~」を付けます。

 ソースファイルを保存するたびにコンパイルを実行するようにしてみましょう。 

[gyro] $ ~compile
[success] Total time: 0 s, completed 2012/12/15 16:18:17
1. Waiting for source changes... (press enter to interrupt)

 「~コマンド名」を実行すると、ソースファイル変更の監視が開始されます。

 「app/controllers/Application.scala」の内容を適当に変更して保存してみてください。保存したタイミングでコンパイルが実行されます。変更の監視を終了したいときはエンターキーを押してください。「~test」とすれば、ソースファイルの保存のたびにテストを実行できます。

Copyright © ITmedia, Inc. All Rights Reserved.

RSSについて

アイティメディアIDについて

メールマガジン登録

@ITのメールマガジンは、 もちろん、すべて無料です。ぜひメールマガジンをご購読ください。