Skip to content

Building a CLI Tool

This tutorial will guide you through creating a simple command-line interface tool in Axon that echoes back arguments with a prefix.

  • Axon compiler installed (v0.1.0 or higher)
  • Basic understanding of S-expressions

Create a new directory and initialize an Axon project using axon-pkg:

Terminal window
mkdir echo-cli
cd echo-cli
axon init

This will generate a project.axs manifest file and a src/main.axs file.

In Axon, command line arguments are accessed via the std/os standard library module. Open src/main.axs and replace its contents with:

(import std/os)
(import std/io)
(fn main ()
(let args (os.args))
(if (<= (len args) 1)
(do
(io.println "Usage: echo-cli <message>")
(os.exit 1))
;; Else, echo the arguments
(let message (join (slice args 1 (len args)) " "))
(io.println (+ "Echo: " message))))

To compile the tool into a standalone native binary, run:

Terminal window
axon build --release

Because Axon compiles directly to machine code via LLVM, this will produce a highly optimized binary in the build/ directory without any dependencies on an interpreter or virtual machine.

Test your new CLI tool:

Terminal window
./build/echo-cli "Hello Axon World!"

Output:

Echo: Hello Axon World!

Congratulations! You’ve just built your first high-performance native CLI tool using Axon.