Defining a command

When creating snapcraft.yaml to build a new snap, its executable components are built from parts, following the Snapcraft lifecycle, and selectively made available to the host system.

Exposing executable components

A snap’s executable is exposed to the host system via the top-level apps section of snapcraft.yaml. Its name needs to correspond with with part name responsible for staging the executable within your snap.

For example, here’s a complete snapcraft.yaml for a fully-functional snap:

name: os-release
base: core18
version: '0.1'
summary: Outputs the contents of /etc/os-release
description: Prints the contents of os-release
grade: stable
confinement: strict
    command: bin/
    plugin: dump
    source: .
    organize: bin/

The above example creates a snap from the following simple script, called, and located within the top-level snap of the directory:

#! /bin/sh
cat /etc/os-release

The executable is brought into the snap via part-os-release, which is a part using the dump plugin. It then uses organize to to copy the file into the snap’s bin/ directory before the top-level apps section exposes the bin/ executable to the host system

For further details on other metadata, see Snapcraft app and service metadata and to define an executable as a service or a daemon, see Services and daemons.

Last updated 2 months ago. Help improve this document in the forum.