State and actions

remainingCommands: List[Exec] returns the remaining commands to
be run

attributes: AttributeMap contains generic data.

The action part of a command performs work and transforms State. The
following sections discuss State => State transformations. As
mentioned previously, a command will typically handle a parsed value as
well: (State, T) => State.

Command-related data

A Command can modify the currently registered commands or the commands
to be executed. This is done in the action part by transforming the
(immutable) State provided to the command. A function that registers
additional power commands might look like:

The first adds a command that will run after all currently specified
commands run. The second inserts a command that will run next. The
remaining commands will run after the inserted command completes.

To indicate that a command has failed and execution should not continue,
return state.fail.

Here, a SettingKey[T] is typically obtained from
Keys and is the same type that is used to
define settings in .sbt files, for example.
Scope selects the scope the key is
obtained for. There are convenience overloads of in that can be used
to specify only the required scope axes. See
Structure.scala for where in
and other parts of the settings interface are defined. Some examples:

import Keys._
val extracted: Extracted
import extracted._
// get name of current project
val nameOpt: Option[String] = name in currentRef get structure.data
// get the package options for the `test:packageSrc` task or Nil if none are defined
val pkgOpts: Seq[PackageOption] = packageOptions in (currentRef, Test, packageSrc) get structure.data getOrElse Nil

Classpaths

Classpaths in sbt 0.10+ are of type Seq[Attributed[File]]. This allows
tagging arbitrary information to classpath entries. sbt currently uses
this to associate an Analysis with an entry. This is how it manages
the information needed for multi-project incremental recompilation. It
also associates the ModuleID and Artifact with managed entries (those
obtained by dependency management). When you only want the underlying
Seq[File], use files:

Running tasks

It can be useful to run a specific project task from a
command (not from another task) and get its result. For
example, an IDE-related command might want to get the classpath from a
project or a task might analyze the results of a compilation. The
relevant method is Project.runTask, which has the following
signature: