Locked History Actions

Diff for "sbt/Getting-Started-Running"

Differences between revisions 3 and 4
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
例えば、プンプでcompileとタイプする 例えば、プンプでcompileとタイプする
Line 27: Line 27:
対話モードを終了させたいときは、exitとタイプするか、あるいはCtrl+D(Unitの場合)あるいはCtrl+Z(Windowsの場合)。 対話モードを終了させたいときは、exitとタイプするか、あるいはCtrl+D(Unixの場合)あるいはCtrl+Z(Windowsの場合)。
Line 72: Line 72:
Interactive mode has tab completion, including at an empty prompt. A special sbt convention is that pressing tab once may show only a subset of most likely completions, while pressing it more times shows more verbose choices. 対話モードではタブ補完ができる。プロンプトが空の状態でもできるよ。
一度押せば代表的なものが示され、複数押せばより詳細なものが示される。
Line 76: Line 78:
Interactive mode remembers history, even if you exit sbt and restart it. The simplest way to access history is with the up arrow key. The following commands are also supported: 対話モードでは履歴を記憶してる。たとえいったんsbtをexitして再起動してもだ。
最も簡単な履歴アクセス方としては、上矢印キーだが、以下のコマンドもある。
Line 78: Line 81:
 * ! Show history command help.
 *   !! Execute the previous 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'

 *
! Show history command help.
 * !! Execute the previous 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'

sbtの実行

https://github.com/harrah/xsbt/wiki/Getting-Started-Runningの翻訳(2011/10/26時点)

ここでは、プロジェクトをセットアップした後のsbtの使い方をみていく。 sbtをインストールして、Hello, Worldか何かのプロジェクトを作成済であることが前提だ。

対話モード

プロジェクトディレクトリの中で引数無しでsbtを起動する

$ sbt

コマンド引数なしで起動すると対話モードになる。 対話モードではコマンドプロンプトが使える(しかもタブ補完と履歴付き!)

例えば、プロンプトでcompileとタイプする

> compile

もう一度コンパイルしたいときは、上矢印を押してEnterを押せばいい。

君のプログラムを起動したい場合はrunだ。

対話モードを終了させたいときは、exitとタイプするか、あるいはCtrl+D(Unixの場合)、あるいはCtrl+Z(Windowsの場合)。

バッチモード

sbtをバッチモードで起動することもできる。 これには、空白で区切られたsbtのアクションを引数として与えればいい。

引数をとるsbtコマンドに対しては、コマンドと引数をクォートで囲む。こんなふうに

$ sbt clean compile "test-only TestA TestB"

この例では、test-onlyにTestAとTestBという引数が与えられる。 そして、示された順(clean, compile, test-only)にアクションが実行される。

継続的なビルドとテスト

edit-compile-testサイクルを素早くするには、君がソースファイルを保存した途端に自動的にコンパイルされるといいよね。

ソースファイルを変更しすると同時にアクションを実行するには、そのアクションの前に~を指定する。例えば、対話モードで以下のようにしてみよう

> ~ compile

変更監視モードを抜けるにはEnterを押すこと。これは対話モードでもバッチモードでも使える。

詳細は「Triggered Execution」を参照のこと

共通アクション

以下は代表的なsbtコマンドだ。完全なリストは「Command Line Reference」を見て欲しい

  • clean: (targetディレクトリ中の)すべての生成ファイルを削除する
  • compile:メインソース(src/main/scalaとsrc/main/javaディレクトリ)をコンパイルする
  • test:全テストをコンパイルして実行する
  • console:コンパイル済ソースと全ての依存をパスに入れてScalaインタプリタを実行する。sbtに戻るには:quit、Ctrl+D (Unix)、あるいはCtrl+Z (Windows)とする。
  • run <argument>*:sbtを実行する同じ仮想マシン上でプロジェクトのメインクラスを実行する

  • package:jarファイルを作成する。これには、src/main/resourcesのファイルと、src/main/scala、src/main/javaをコンパイルしたものが含まれる
  • help <command>:指定されたコマンドの詳細ヘルプを表示する。コマンドが指定されなければ、全コマンドについて簡易説明を表示する

  • reload:ビルド定義を再ロードする。(build.sbt, project/*.scala, project/*.sbt files)。ビルド定義を変更したらこれが必要。

タブ補完

対話モードではタブ補完ができる。プロンプトが空の状態でもできるよ。 一度押せば代表的なものが示され、複数押せばより詳細なものが示される。

履歴コマンド

対話モードでは履歴を記憶してる。たとえいったんsbtをexitして再起動してもだ。 最も簡単な履歴アクセス方としては、上矢印キーだが、以下のコマンドもある。

  • ! Show history command help.
  • !! Execute the previous 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'