diff options
Diffstat (limited to 'bin/ak')
| -rwxr-xr-x | bin/ak | 105 |
1 files changed, 93 insertions, 12 deletions
@@ -1,5 +1,24 @@ -#!/bin/bash -export AK_DEBUG="yes" +#!/usr/bin/env bash +### +### arching-kaos-tools +### Tools to interact and build an Arching Kaos Infochain +### Copyright (C) 2021 - 2025 kaotisk +### +### This program is free software: you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation, either version 3 of the License, or +### (at your option) any later version. +### +### This program is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with this program. If not, see <http://www.gnu.org/licenses/>. +### +export AK_DEBUG=0 +export AK_DEBUG_IRC="no" ## ## Arching Kaos CLI tool is the main executable script to use for exploring, ## creating and distributing local blockchain(s) called zchain(s). @@ -10,11 +29,17 @@ export AK_DEBUG="yes" ## ## Run with no arguments to see available commands ## -## -h, --help Prints this help message +## -h, --help Prints this help message. +## +## -s, --shell Starts an interactive shell. ## ## -m, --module [module] Run a specified module. If no module provided ## the list of available modules will be printed. ## +## -f, --function [function] Get the list of available functions. +## +## -v Print all log messages. +## ## [command] [args] Run a command. If none provided a list of ## commands will be printed. ## @@ -23,12 +48,51 @@ PROGRAM="$(basename $0)" descriptionString="Arching Kaos CLI" source $HOME/.arching-kaos/rc -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_lib_load +_ak_lib_load _ak_log +_ak_lib_load _ak_script + +if [ "$1" == "-vi" ] +then + export AK_DEBUG_IRC="yes" + export AK_DEBUG="no" + shift +fi +if [ "$1" == "-vn" ] +then + export AK_DEBUG="no" + shift +fi +if [ "$1" == "-vvvvv" ] +then + export AK_DEBUG=5 + shift +fi +if [ "$1" == "-vvvv" ] +then + export AK_DEBUG=4 + shift +fi +if [ "$1" == "-vvv" ] +then + export AK_DEBUG=3 + shift +fi +if [ "$1" == "-vv" ] +then + export AK_DEBUG=2 + shift +fi +if [ "$1" == "-v" ] +then + export AK_DEBUG=1 + shift +fi if [ $# -eq 0 ] then _ak_log_warning "No command given" + _ak_log_info "Available commands:" ( find $AK_BINDIR | grep 'ak-' | while read available do @@ -37,11 +101,11 @@ then args="-h" if [ -n "$subcmd" ] then - echo $subcmd | cut -d '-' -f 2 | sort | uniq | sed -e 's/^/ak /g' + echo $subcmd | cut -d '-' -f 2 | sort | uniq #| sed -e 's/^/ak /g' #$(echo $subcmd) $args fi done - ) | sort | uniq + ) | sort | uniq #| sed 's/^/# /g' | while read line; do _ak_log_info "$line";done exit 1 fi @@ -52,6 +116,10 @@ then _ak_usage exit 1 ;; + -v|--version) + _ak_version + exit 1 + ;; esac fi @@ -68,7 +136,7 @@ case "$1" in shift if [ ! -z $1 ] && [ -n "$1" ] then - grep -rnF "$1(){" $AK_BINDIR/* $AK_LIBDIR/* $AK_MODULESDIR/* + grep -rnF "$1(){" $AK_BINDIR/* $AK_LIBDIR/* $AK_MODULESDIR/* > /dev/null 2>&1 if [ $? -ne 0 ] then _ak_log_error "No function $1 found" @@ -81,13 +149,20 @@ case "$1" in fi filename="$(grep -rnF "$1(){" $AK_LIBDIR/* $AK_MODULESDIR/* | cut -d ':' -f 1)" line="$(grep -rnF "$1(){" $AK_LIBDIR/* $AK_MODULESDIR/* | cut -d ':' -f 2)" - functionname="$(grep -rnF "$1(){" $AK_LIBDIR/* $AK_MODULESDIR/* | cut -d ':' -f 3)" - printf 'Use with:\n' >&2 + functionname="$(grep -rnF "$1(){" $AK_LIBDIR/* $AK_MODULESDIR/* | cut -d ':' -f 3|sed -e 's/function //g')" + _ak_log_info "Use with:" printf 'source %s\n%s\n' "$filename" "$(echo -n $functionname | sed 's/(){//')" exit else + _ak_log_error "No function selected" + _ak_log_info "Available functions:" grep -rnF "(){" $AK_LIBDIR/* $AK_MODULESDIR/* | \ - sed -e "s#$AK_WORKDIR/##g" | sed -e 's/(){//g' | cut -d ':' -f 1,3 | tr ':' $'\t' + sed -e "s#$AK_WORKDIR/##g" | \ + sed -e 's/function //g;s/(){//g' | \ + cut -d ':' -f 1,3 | \ + tr ':' ' ' | \ + awk '{print $1 " " $2}' | \ + sort | while read line; do _ak_log_info "${line}"; done exit fi ;; @@ -100,7 +175,8 @@ case "$1" in if [ ! -n "$1" ] then _ak_log_error "No module selected" - ls -1 $AK_MODULESDIR + _ak_log_info "Modules available:" + ls -1 $AK_MODULESDIR | sed 's/^/# /g' | while read line; do _ak_log_info "$line";done exit 1 fi shift @@ -117,6 +193,10 @@ case "$1" in $subcmd/main.sh $subargs _ak_exit_program $? "$subcmd module finished"; ;; + -s|--shell) + rlwrap ak sh -s + _ak_exit_program $? "Shell terminated"; + ;; esac if [ -f "$AK_BINDIR/ak-$subcmd" ] @@ -139,6 +219,7 @@ else fi counter=$(($counter + 1)) done + # _ak_usage err find $AK_BINDIR | while read available do echo $(basename $available) |\ |
