Akd v0.2.1 Akd.Destination View Source

This module represents a Destination struct which contains metadata about a destination/location/host.

The meta data involves:

  • user - Represents the user who will be accessing a host/server. Expects a string, defaults to :current.
  • host - Represents the host/server being accessed. Expects a string, defaults to :local.
  • path - Represents the path on the server being accessed. Expects a string, defaults to . (current directory).

Example:

  • Accessing root@x.x.x.x:/path/to/dir" would have:

    • user: "root"
    • host: "x.x.x.x"
    • path: "/path/to/dir/"

This struct is mainly used by native hooks in Akd, but it can be leveraged to produce custom hooks.

Link to this section Summary

Types

A Akd.Destination.host can be either a string or :local

t()

Generic type for Akd.Destination

A Akd.Destination.user can be either a string or :current

Functions

Takes a string path and returns a local Akd.Destination.t struct which corresponds to locahost with the given path

Takes a readable string and converts it to an Akd.Destination.t struct. Expects the string to be in the following format: <user>@<host>:<path> and parses it to: %Akd.Destination{user: <user>, host: <host>, path: <path>}

Takes an Akd.Destination.t struct, dest and parses it into a readable string

Link to this section Types

Link to this type host() View Source
host() :: String.t() | :local

A Akd.Destination.host can be either a string or :local

Link to this type t() View Source
t() :: %Akd.Destination{host: host(), path: String.t(), user: user()}

Generic type for Akd.Destination

Link to this type user() View Source
user() :: String.t() | :current

A Akd.Destination.user can be either a string or :current

Link to this section Functions

Takes a string path and returns a local Akd.Destination.t struct which corresponds to locahost with the given path.

Alternatively one can initialize an Akd.Destination.t struct with just a path, which will return a local Destination struct by default

Examples

When a path is given:

iex> Akd.Destination.local("/fus/ro/dah")
%Akd.Destination{host: :local, path: "/fus/ro/dah", user: :current}

Takes a readable string and converts it to an Akd.Destination.t struct. Expects the string to be in the following format: <user>@<host>:<path> and parses it to: %Akd.Destination{user: <user>, host: <host>, path: <path>}

Raises a MatchError if the string isn’t in the correct format.

Examples

When a string with the correct format is given:

iex> Akd.Destination.parse("dragonborn@skyrim:whiterun")
%Akd.Destination{user: "dragonborn", host: "skyrim", path: "whiterun"}

When a wrongly formatted string is given:

iex> Akd.Destination.parse("arrowtotheknee")
** (MatchError) no match of right hand side value: ["arrowtotheknee"]

Takes an Akd.Destination.t struct, dest and parses it into a readable string.

Examples

When dest is a local destination:

iex> params = %{user: :current, host: :local, path: "/path/to/dir"}
iex> local_destination = struct!(Akd.Destination, params)
iex> Akd.Destination.to_string(local_destination)
"/path/to/dir"

When dest remote destination:

iex> params = %{user: "dragonborn", host: "skyrim", path: "whiterun"}
iex> local_destination = struct!(Akd.Destination, params)
iex> Akd.Destination.to_string(local_destination)
"dragonborn@skyrim:whiterun"