basic-cli-builder 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- basic_cli_builder-0.1.0/PKG-INFO +8 -0
- basic_cli_builder-0.1.0/pyproject.toml +13 -0
- basic_cli_builder-0.1.0/setup.cfg +4 -0
- basic_cli_builder-0.1.0/src/basic_cli/__init__.py +1 -0
- basic_cli_builder-0.1.0/src/basic_cli/arguments.py +17 -0
- basic_cli_builder-0.1.0/src/basic_cli/command.py +7 -0
- basic_cli_builder-0.1.0/src/basic_cli/parser.py +32 -0
- basic_cli_builder-0.1.0/src/basic_cli/text_manager.py +17 -0
- basic_cli_builder-0.1.0/src/basic_cli_builder.egg-info/PKG-INFO +8 -0
- basic_cli_builder-0.1.0/src/basic_cli_builder.egg-info/SOURCES.txt +13 -0
- basic_cli_builder-0.1.0/src/basic_cli_builder.egg-info/dependency_links.txt +1 -0
- basic_cli_builder-0.1.0/src/basic_cli_builder.egg-info/top_level.txt +1 -0
- basic_cli_builder-0.1.0/tests/test_arguments.py +13 -0
- basic_cli_builder-0.1.0/tests/test_parser.py +17 -0
- basic_cli_builder-0.1.0/tests/test_text_manager.py +10 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: basic-cli-builder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple Python library for creating command-line interfaces.
|
|
5
|
+
Author-email: blindpro <noahbalboa34@gmail.com>
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "basic-cli-builder"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A simple Python library for creating command-line interfaces."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "GPL-3.0-or-later"
|
|
7
|
+
requires-python = ">=3.9"
|
|
8
|
+
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "blindpro", email = "noahbalboa34@gmail.com" }
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
dependencies = []
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import parser
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from.text_manager import get_flags, get_options
|
|
2
|
+
class arguments():
|
|
3
|
+
def __init__(self,text):
|
|
4
|
+
self.text = text
|
|
5
|
+
self.options = get_options(text)
|
|
6
|
+
self.flags = get_flags(text)
|
|
7
|
+
def has_option(self,option):
|
|
8
|
+
new_option = option
|
|
9
|
+
if option.startswith("-") == False:
|
|
10
|
+
new_option = f"-{option}"
|
|
11
|
+
return new_option in self.options
|
|
12
|
+
def has_flag(self,flag):
|
|
13
|
+
new_flag = flag
|
|
14
|
+
if flag.startswith("--") == False:
|
|
15
|
+
new_flag = f"--{flag}"
|
|
16
|
+
return new_flag in self.flags
|
|
17
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from sys import exit
|
|
2
|
+
from .command import command
|
|
3
|
+
from . import text_manager as text
|
|
4
|
+
from .arguments import arguments
|
|
5
|
+
class parser():
|
|
6
|
+
def __init__(self,name):
|
|
7
|
+
self.commands = {}
|
|
8
|
+
self.name = name
|
|
9
|
+
def add_command(self,name,action,help_text = ""):
|
|
10
|
+
self.commands[name] = command(name,action,help_text)
|
|
11
|
+
def parse(self,input):
|
|
12
|
+
input = str(input)
|
|
13
|
+
base = text.get_base(input)
|
|
14
|
+
if base == self.name:
|
|
15
|
+
print(f"{name}, type {name} help for usage")
|
|
16
|
+
elif base == "exit" or input == "quit":
|
|
17
|
+
exit()
|
|
18
|
+
elif base == help:
|
|
19
|
+
self.help()
|
|
20
|
+
return
|
|
21
|
+
elif base not in self.commands:
|
|
22
|
+
print("invalid command")
|
|
23
|
+
else:
|
|
24
|
+
args = arguments(input)
|
|
25
|
+
to_run = self.commands[base]
|
|
26
|
+
to_run.run(args)
|
|
27
|
+
def help(self):
|
|
28
|
+
print("usage")
|
|
29
|
+
for key,value in self.commands.items():
|
|
30
|
+
print(key)
|
|
31
|
+
print(value.help_text)
|
|
32
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
def get_base(text):
|
|
2
|
+
parts = text.split(" ")
|
|
3
|
+
return parts[0]
|
|
4
|
+
def get_options(text):
|
|
5
|
+
options = []
|
|
6
|
+
parts = text.split(" ")
|
|
7
|
+
for item in parts:
|
|
8
|
+
if item.startswith("-") and item.count("-") == 1:
|
|
9
|
+
options.append(item)
|
|
10
|
+
return options
|
|
11
|
+
def get_flags(text):
|
|
12
|
+
flags = []
|
|
13
|
+
parts = text.split(" ")
|
|
14
|
+
for item in parts:
|
|
15
|
+
if item.startswith("--") and item.count("-") == 2:
|
|
16
|
+
flags.append(item)
|
|
17
|
+
return flags
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: basic-cli-builder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple Python library for creating command-line interfaces.
|
|
5
|
+
Author-email: blindpro <noahbalboa34@gmail.com>
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
src/basic_cli/__init__.py
|
|
3
|
+
src/basic_cli/arguments.py
|
|
4
|
+
src/basic_cli/command.py
|
|
5
|
+
src/basic_cli/parser.py
|
|
6
|
+
src/basic_cli/text_manager.py
|
|
7
|
+
src/basic_cli_builder.egg-info/PKG-INFO
|
|
8
|
+
src/basic_cli_builder.egg-info/SOURCES.txt
|
|
9
|
+
src/basic_cli_builder.egg-info/dependency_links.txt
|
|
10
|
+
src/basic_cli_builder.egg-info/top_level.txt
|
|
11
|
+
tests/test_arguments.py
|
|
12
|
+
tests/test_parser.py
|
|
13
|
+
tests/test_text_manager.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
basic_cli
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from basic_cli.arguments import arguments
|
|
2
|
+
def test_options():
|
|
3
|
+
args = arguments("base -option --flag")
|
|
4
|
+
assert args.has_option("-option") == True
|
|
5
|
+
def test_flags():
|
|
6
|
+
args = arguments("base -option --flag")
|
|
7
|
+
assert args.has_flag("--flag") == True
|
|
8
|
+
def test_auto_dash_option():
|
|
9
|
+
args = arguments("base -option --flag")
|
|
10
|
+
assert args.has_option("option") == True
|
|
11
|
+
def test_auto_dash_flag():
|
|
12
|
+
args = arguments("base -option --flag")
|
|
13
|
+
assert args.has_flag("flag") == True
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from basic_cli.parser import parser
|
|
2
|
+
p = parser("tester")
|
|
3
|
+
def test_invalid(capsys):
|
|
4
|
+
p.parse("this is invalid")
|
|
5
|
+
captured = capsys.readouterr()
|
|
6
|
+
assert captured.out == "invalid command\n"
|
|
7
|
+
def test_random(capsys):
|
|
8
|
+
p.parse(26)
|
|
9
|
+
captured = capsys.readouterr()
|
|
10
|
+
assert captured.out == "invalid command\n"
|
|
11
|
+
def greet(args):
|
|
12
|
+
print("hi!")
|
|
13
|
+
p.add_command("greet",greet,"Greets.")
|
|
14
|
+
def test_command_runner(capsys):
|
|
15
|
+
p.parse("greet")
|
|
16
|
+
captured = capsys.readouterr()
|
|
17
|
+
assert captured.out == "hi!\n"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from basic_cli import text_manager as text
|
|
2
|
+
def test_get_base():
|
|
3
|
+
output = text.get_base("base arg arg --flag")
|
|
4
|
+
assert output == "base"
|
|
5
|
+
def test_options():
|
|
6
|
+
options = text.get_options("base -option1 -option2 --flag")
|
|
7
|
+
assert len(options) == 2
|
|
8
|
+
def test_flags():
|
|
9
|
+
flags = text.get_flags("base -option -another_option --f --flag --third_flag")
|
|
10
|
+
assert len(flags) == 3
|