@nix2/nix-cli

Command line interface for common tasks for Nix2 Infrastructure


Keywords
cli, nix2, typescript
License
CC-BY-1.0
Install
npm install @nix2/nix-cli@1.0.3

Documentation

CLI Logo

Nix² CLI
this cli will allow nix² developers to easily create, modify, and maintain their services

[ Installation 💾 | Usage 🤓 | NPM 📦 | Github 🕸 ]

CLI Screenshot

Installation

All you need is to install is node

$ npm i -g @nix2/nix-cli

Usage

The basic command is nix-cli which if you are using the zsh plugin you are given an alias of dev. The rest of the documentation uses dev but should be the same for nix-cli.

When running the command with no arguments, it will default to dev info.

Table of Contents

Commands

This CLI is built with commander.js, which generates help screens based off the structure of the application. To get help on any commands, just run dev help.

$ dev help

Usage: nix-cli [options] [command]

Options:
  -v                        output cli version
  -h, --help                display help for command

Commands:
  auth                      authenticate to a user account
  info                      display service context info
  init [options] [dirname]  initialize a service
  make                      make things related to your service
  authors                   manage your authors
  cache                     manage your cache
  help [command]            display help for command

Auth

Authenticate the CLI user.

NOTE This is currently WIP so it is a mock authentication.

Init

Initialize a service.

The init command needs to be provided a service type. If there is no service provided as the agument, it will prompt the user to select all the valid service types from a list.

Here are the two ways you can initialize.

$ dev init
? Select the type
> typescript
  graphql

$ dev init graphql

After selecting the service type, it will prompt you on filling in details for the service. Each service has different initialize data but there are four options that all are asked for, no matter the service type.

Name Description Default
identifier Service Identifier Taken from the directory name
label Service Label (for humans) Taken from the service ID
description Service Description "A Nix² Service"
userLeadDev Makes the user the leadDev true

Info

The info command will give you basic info on your current Service Context.

$ dev info

Nix2 CLI version 1.0.1
local data from service.yaml
|
|  Blog (blog)
|  The blog service
|  v1.0.0  -  1 dev
|

Make

The make command allows a developer to make certain services that are supported by a service. The access to files that can be created with make depends on your plugin configuration. Each service has different files that can be created with make but there are still some files that are avaliable with all plugins.

Name File Description
readme README.md Creates a README file.
gitignore .gitignore Creates a .gitignore

Database

The database command or db, allows a developer to create, modify, deploy, maintain, and retire a service's database.

Nix2 uses FaunaDB for databases.

Auth

Authenticates yourself with FaunaDB.

List

Lists all the Nix2 databases.

Create

Creates a service database.

Link

Links a service with a database.

Schemas

Functionality for controlling service schemas.

List

Lists basic info for the service's schemas.

A shortcut for this command is dev schemas

$ dev schemas list

Displaying 1 schema
┌──────┬───────┬─────────────┐
│ ID   │ Label │ Description │
├──────┼───────┼─────────────┤
│ user │ User  │ A Serv User │
└──────┴───────┴─────────────┘

Add

Add schemas by their ID.

$ dev schemas add user

⚠  About to write to service.yaml

identifier: 'user'
label: 'User'
pluralName: 'users'
fields:

? Proceed with adding schema? Yes
✔ Schema user added

Remove

Remove schemas by their id.

$ dev schemas remove user

⚠  About to write to service.yaml

identifier: 'user'
label: 'User'
pluralName: 'users'
fields:

? Proceed with removing user? Yes
✔ Schema user removed

You can also use the -y flag to skip the confirmation screen.

Authors

Functionality for controlling service authors.

List

Lists basic info for the service's authors.

A shortcut for this command is dev authors

$ dev authors list

Displaying 2 authors
┌──────────────────────┬──────────┬─────────┐
│ Email                │ Name     │ Flags   │
├──────────────────────┼──────────┼─────────┤
│ maxk@nix2.io         │ Max Koon │ leadDev │
├──────────────────────┼──────────┼─────────┤
│ support@nix2.io      │ Support  │ support │
└──────────────────────┴──────────┴─────────┘

Add

Add authors by their email.

$ dev authors add m@x.com

⚠  About to write to service.yaml

{
  email: 'm@x.com',
  name: 'Max',
  publicEmail: null,
  url: null,
  alert: 'none',
  flags: [ 'dev' ]
}

? Proceed with adding author? Yes
✔ Author m@x.com added

To add data to author you can use different parameters which can be listed with help flag.

This will return:

$ dev authors add --help

Usage: nix-cli authors add [options] <email>

Options:
  -n, --authorName [name]          name of the author
  -E, --publicEmail [publicEmail]  email to use for the public
  -u, --url [url]                  author url
  -a, --alert [alert]              alert options
  -p, --public                     set the public flag
  -d, --dev                        developer flag
  -D, --ldev                       lead dev flag
  -s, --support                    support flag
  -y, --yes                        skip the confirmation screen
  -h, --help                       display help for command

NOTE Each author's data is cached for the most recent usage so you don't need to retype all these parameters each time you add an author. To clear cache please read this

Remove

Remove authors by their email.

$ dev authors remove m@x.com

⚠  About to write to service.yaml

{
  email: 'm@x.com',
  name: 'Max',
  publicEmail: null,
  url: null,
  alert: 'none',
  flags: [ 'dev' ]
}

? Proceed with removing author? Yes
✔ Author m@x.com removed

You can also use the -y flag to skip the confirmation screen.

Plugins

Plugins were added in version 1.1.0, and enhances the scalability of the CLI, and allow for core functions to be separate from the services.

You can manage plugins with the plugin command.

List

$ dev plugins list

----------
graphql
typescript
----------

Add

$ dev plugins add typescript

✓ Installed typescript

Remove

$ dev plugins remove typescript

✓ Removed typescript

Update

$ dev plugins update *

✓ Updated typescript
✓ Updated graphql

NPR

The Nix Plugin Registry is the container of all plugin information. Information including names, descriptions, and versions.

The NPR runs on the npr repository. It functions completely with github actions.

Environment

There are multiple environments for deployed services such as development and production. With the env command you can manage your selected environment

List

List all the available environments

$ dev env list

------------
 - prod
 - dev  (selected)
------------

Switch Environments

$ dev env prod

✔ switched to env: 'prod'

Version

Service versioning follows Semantic Versioning

To get the current version you can run

$ dev version

The 'example-service' is on version 2.0.1

You can bump the version manually by doing:

$ dev version 2.0.2

Updated version to 2.0.2

You can also bump with patch, minor, or major.

$ dev version minor

Updated version to 2.1.0

Update

Updates the CLI with yarn.

$ dev update

✔ Updated the CLI

Cache

Clear

To clear all the cache use:

$ dev cache clear