-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4649c05
commit 9d5909e
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from types as types import Function | ||
|
||
const CLI_NAME*: string = "Line" | ||
const CLI_VERSION*: string = "1.0.0" | ||
const HELP_FUNCTION: string = "help" | ||
const SHORT_HELP_FUNCTION: string = "h" | ||
const VERSION_FUNCTION: string = "version" | ||
const SHORT_VERSION_FUNCTION: string = "v" | ||
const CLI_COPYRIGHT*: string = "Copyright (c) 2023 by Airscript" | ||
|
||
const CLI_FUNCTIONS*: Function = ( | ||
h: SHORT_HELP_FUNCTION, | ||
v: SHORT_VERSION_FUNCTION, | ||
help: HELP_FUNCTION, | ||
version: VERSION_FUNCTION, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from std/strformat import fmt | ||
|
||
from constants as constants import CLI_NAME, CLI_VERSION, CLI_COPYRIGHT | ||
|
||
let usage: string = """ | ||
Usage: | ||
line [options] | ||
""" | ||
|
||
let options: string = """ | ||
Options: | ||
-h, --help Show this help | ||
-v, --version Show the current version | ||
""" | ||
|
||
let help*: string = fmt""" | ||
{CLI_NAME} {CLI_VERSION} | ||
{CLI_COPYRIGHT}{'\n'} | ||
{usage} | ||
{options}""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from std/strformat import fmt | ||
|
||
from descriptions as descriptions import help | ||
from constants as constants import CLI_VERSION | ||
|
||
proc help*(): void = | ||
echo descriptions.help | ||
system.quit(errorcode=QuitSuccess) | ||
|
||
proc version*(): void = | ||
echo fmt"{CLI_VERSION}{'\n'}" | ||
system.quit(errorcode=QuitSuccess) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from std/parseopt import getopt, cmdLongOption, cmdShortOption | ||
|
||
from functions as functions import help, version | ||
|
||
from constants as constants import | ||
CLI_NAME, | ||
CLI_VERSION, | ||
CLI_COPYRIGHT, | ||
CLI_FUNCTIONS | ||
|
||
proc options(option: string): void = | ||
case option: | ||
of CLI_FUNCTIONS.h, CLI_FUNCTIONS.help: help() | ||
of CLI_FUNCTIONS.v, CLI_FUNCTIONS.version: version() | ||
else: help() | ||
|
||
proc cli(): void = | ||
for kind, key, val in getopt(): | ||
case kind | ||
of cmdLongOption, cmdShortOption: options(key) | ||
else: discard | ||
|
||
when isMainModule: | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type | ||
Function* = tuple | ||
h: string | ||
v: string | ||
help: string | ||
version: string |