Skip to main content

Command Line Interface (CLI)

If you want to create ontology concepts, assign them properties, make files and folders, compressing them, and many more, you can do it all using the toolkit.

Installation

Before you begin, make sure your machine meets the following requirements:

  • Linux or Mac OS
  • Docker (https://docs.docker.com/get-docker/)
  • Python 3.8 or higher
  • Pip 20.0 or higher
  • Git
  • Anaconda (optional) (recommended) (for creating virtual environments)

1. Pull Docker Image

Openfabric SDK is a dockerized application. To start working on it, you need to pull the docker image from the docker hub. To do so, run the following command in your terminal:

sudo groupadd docker
sudo usermod -aG docker $USER
docker pull openfabric/toolkit:latest

2. Run Docker Image

The toolkit can be launched in interactive mode by running the following command:

docker run --network="host" -i --rm \
--user `id -u ${USER}`:`id -g ${USER}` \
-v ${PWD}:${PWD} -w ${PWD} \
openfabric/toolkit:latest

3. Create a shell script

It's better to create a folder for Openfabric and use that as the working directory. For example, create a folder called openfabric in your home directory and use that as the working directory.

mkdir ~/openfabric
cd ~/openfabric

Now, you no longer need to execute the docker run command every time you wish to utilize the SDK. Instead, you can create a shell script to handle the specified parameters. Simply create a new file openfabric-toolkit.sh in ~/openfabric/ or anywhere else in your system with the code provided below.

openfabric-toolkit.sh contents:

#!/bin/bash
set -e

IMAGE_TAG=openfabric/toolkit:latest
unset EXTRA_ARGS

while true
do
# Check if --update is passed as the first argument
if test "$1" = "--update"; then
EXTRA_ARGS="${EXTRA_ARGS} --pull=always"
shift
elif test "$1" = "--no-terminal"; then
NO_TERMINAL=y
shift
else
break
fi
done

if [[ $# -eq 0 ]]; then
if [[ -z $NO_TERMINAL ]]; then
# Interactive mode, enable tty, unless '--no-terminal' is specified
EXTRA_ARGS="${EXTRA_ARGS} -t"
fi
fi


# NOTE: host network driver is not supported on mac and windows,
# therefore we need to expose the used ports in another way
case "$(uname -s)" in

Darwin)
# Mac OS X
docker run \
-p 8741:8741\
-i --rm \
-v ${PWD}:${PWD} \
-v /tmp:/tmp \
-v /var/run/docker.sock:/var/run/docker.sock \
${EXTRA_ARGS} \
-w ${PWD} ${IMAGE_TAG} "$@"
;;

CYGWIN*|MINGW32*|MSYS*|MINGW*)
# MS Windows
docker run \
-p 8741:8741\
-i --rm \
-v ${PWD}:${PWD} \
-v /tmp:/tmp \
-v /var/run/docker.sock:/var/run/docker.sock \
${EXTRA_ARGS} \
-w ${PWD} ${IMAGE_TAG} "$@"
;;

Linux)
# Linux
docker run --network="host" ${EXTRA_ARGS} -i --rm --user `id -u ${USER}`:`id -g ${USER}` -v ${PWD}:${PWD} -w ${PWD} ${IMAGE_TAG} "$@"
;;

*)
# Unknonwn OS, attempt same as on linux
docker run --network="host" ${EXTRA_ARGS} -i --rm --user `id -u ${USER}`:`id -g ${USER}` -v ${PWD}:${PWD} -w ${PWD} ${IMAGE_TAG} "$@"
;;
esac
  • add the path to the file to the system path: echo 'PATH=~/openfabric:${PATH}' >> ~/.bashrc. If openfabric is not your path then replace it with the path to the file.
  • update it's permissions to enable execution: sudo chmod 755 ~/openfabric/openfabric-toolkit.sh. If openfabric is not your path then replace it with the path to the file.

3. Add a global alias

This instruction is about making a command line tool globally available on your computer. You should add the following line to your ~/.bashrc or ~/.zshrc file: /home/user isn't necessary, you can add any custom path to the file.

export PATH="$PATH:~/openfabric"

This line will add the openfabric-cli directory to your system's PATH, which means that you can run any command line tool located in that directory from anywhere on your computer.

In addition, you can create an alias for the command line tool to make it easier to use. For example, you can create an alias called ofc for the openfabric-toolkit.sh tool by adding the following line to your configuration file:

alias ofc="openfabric-toolkit.sh"

Now, whenever you type ofc in the command line, it will run the openfabric-toolkit.sh script.

Finally, if you are using a Linux system, you also need to set the DOCKER_GATEWAY_HOST environment variable by adding the following line to your configuration file:

export DOCKER_GATEWAY_HOST=`hostname -I |awk '{print $1}'`

This will set the DOCKER_GATEWAY_HOST variable to the IP address of your computer, which is required for running Docker containers.

What are you able to do now?

Now, you can run the toolkit by simply typing ofc in your terminal. You can also run the toolkit in any directory you want. The toolkit will be able to access the files in the directory you are running it from.

If you want to create ontology concepts, assign them properties, make files and folders, compressing them, and many more, you can do it all using the toolkit.

Congratulations! You have successfully setup your machine to start working on Openfabric SDK.

Command Overview

For an extensive guide to the CLI toolkit's commands, consult the table below. This resource offers in-depth descriptions, practical usage tips, and illustrative examples for each command, equipping developers with the knowledge needed for proficient application in their projects.

NameDescription
newThe command is engineered to generate a structural component (ontology, concept, or properties) for Openfabric development or integration purposes.
genThe command is designed to facilitate the generation of project assets for Openfabric's applications.
integrateThe command is designed to start the integration wizard between Openfabric and the selected project.
packThe command, designed to create a TAR archive encompassing all AI app files, facilitates deployment of the AI application to Openfabric Xplorer.
OpenfabricAI Robot
OpenfabricAI FooterOpenfabricAI Footer