Dicon.Executor behaviour (Dicon v0.6.0)

Copy Markdown View Source

Behaviour for executors.

This behaviour specifies the callbacks that executors must implement. Look at the documentation for the Dicon module for more information about executors.

Summary

Callbacks

Connects to the given authority, returning a term that identifies the connection.

Copies the local file source over to the destination target on the given connection.

Executes the given command on the given connection, writing the output of command to device.

Functions

Connects to authority.

Copies the source file on the local machine to the target on the remote machine on the connection in state.

Executes the given command on the connection in state.

Types

conn()

@type conn() :: identifier() | struct()

t()

@type t() :: %Dicon.Executor{conn: conn(), executor: module()}

Callbacks

connect(authority)

@callback connect(authority :: binary()) :: {:ok, conn()} | {:error, binary()}

Connects to the given authority, returning a term that identifies the connection.

copy(conn, source, target)

@callback copy(conn(), source :: charlist(), target :: charlist()) ::
  :ok | {:error, binary()}

Copies the local file source over to the destination target on the given connection.

exec(conn, command, device)

@callback exec(conn(), command :: charlist(), device :: atom() | pid()) ::
  :ok | {:error, binary()}

Executes the given command on the given connection, writing the output of command to device.

write_file(conn, target, content, arg4)

@callback write_file(conn(), target :: charlist(), content :: iodata(), :write | :append) ::
  :ok | {:error, binary()}

Functions

connect(authority)

@spec connect(binary()) :: {:ok, t()} | {:error, term()}

Connects to authority.

The connection happens through the executor configured in the configuration for the :dicon application; see the documentation for the Dicon module for more information.

Examples

%Dicon.Executor{} = Dicon.Executor.connect("meg:secret@example.com")

copy(state, source, target)

Copies the source file on the local machine to the target on the remote machine on the connection in state.

Examples

state = Dicon.Executor.connect("meg:secret@example.com")
Dicon.Executor.copy(state, "hello.txt", "uploaded-hello.txt")
#=> :ok

exec(state, command, device \\ Process.group_leader())

Executes the given command on the connection in state.

Examples

state = Dicon.Executor.connect("meg:secret@example.com")
Dicon.Executor.exec(state, "ls -la")
#=> :ok

write_file(state, target, content, mode \\ :write)