create

gest artifact create: create a new artifact.

struct Command

source

pub struct Command

Create a new artifact.

When stdin is piped, the first markdown heading (# …) is used as the title and the full input becomes the body. A title can also be given as a positional argument, in which case stdin (if piped) is used as the body only.

Field Type Description
title Option<String> The artifact title (extracted from the first # heading when piping stdin).
batch bool Read NDJSON artifacts from stdin (one JSON object per line).
body Option<String> The artifact body (markdown; opens $EDITOR if omitted and stdin is a terminal).
iteration Option<String> Link the artifact to an iteration by ID or prefix.
metadata Vec<String> Set a metadata key=value pair (repeatable; supports dot-paths and scalar inference).
metadata_json Vec<String> Merge a JSON object into metadata (repeatable; applied after –metadata pairs).
source Option<String> Read the body from a file path instead of stdin or $EDITOR.
tag Vec<String> Add a tag to the artifact (can be repeated; comma-separated values split into multiple tags).
output json::Flags The output mode: normal, --json, --quiet or --raw.

Implements FromArgMatches, Args, Debug.

Command::call

source

pub async fn call(&self, context: &AppContext) -> Result<(), Error>

Insert a new artifact (or a batch from NDJSON stdin), attaching tags and any iteration link.

Parameter Type Description
context &AppContext the application context: settings, store and current project
returns Result<(), Error> Ok(()) when the command succeeds, or the error that stopped it.

Command::call_batch

source

async fn call_batch(&self, context: &AppContext) -> Result<(), Error>

Create one artifact for each NDJSON line on stdin, all in one SQL transaction.

Parameter Type Description
context &AppContext the application context: settings, store and current project
returns Result<(), Error> Ok(()) once every artifact is created and printed, or the first error; a record that fails rolls back the whole batch.

Command::parse_metadata

source

fn parse_metadata(&self) -> Result<Option<Value>, Error>

Build the metadata from the --metadata and --metadata-json options.

Parameter Type Description
returns Result<Option<Value>, Error> The metadata object, None when neither option is given, or Error::Argument for a bad value.

Command::resolve_title_and_body

source

fn resolve_title_and_body(&self) -> Result<(String, String), Error>

Find the title and body from the arguments, a --source file, $EDITOR or piped stdin.

With a title argument, the body comes from --source, then --body, then $EDITOR when stdin is a terminal, then stdin. With no title and piped stdin, the first # heading is the title and the whole input is the body.

Parameter Type Description
returns Result<(String, String), Error> The title and the body, Error::Argument when there is no title, or Error::Editor when the source file or the editor fails.

struct BatchRecord

source

struct BatchRecord

A single artifact record in NDJSON batch mode.

Field Type Description
body Option<String> The markdown body; empty when absent.
iteration Option<String> An iteration ID or prefix to link the artifact to.
metadata Option<Value> The metadata to store as it is.
tags Option<Vec<String>> Tag labels to attach, used as given.
title String The artifact title, the one required key.

Implements Debug, Deserialize<'de>.

fn create_batch_records

source

async fn create_batch_records(
    project_id: &Id,
    conn: &Connection,
    input: &str,
) -> Result<Vec<Model>, Error>

Create every artifact described in the NDJSON input, applying tags and any iteration link; intended to run inside an explicit SQL transaction wrapper.

Parameter Type Description
project_id &Id the project that owns the new artifacts
conn &Connection the connection that holds the open SQL transaction
input &str the NDJSON text, one [BatchRecord] for each non-blank line
returns Result<Vec<Model>, Error> The created artifacts in input order, or Error::Argument for a line that is not a valid record.