basic-cli-builder 0.1.0__py3-none-any.whl

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/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from . import parser
basic_cli/arguments.py ADDED
@@ -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
+
basic_cli/command.py ADDED
@@ -0,0 +1,7 @@
1
+ class command():
2
+ def __init__(self,name,action,help_text):
3
+ self.name = name
4
+ self.action = action
5
+ self.help_text = help_text
6
+ def run(self,args):
7
+ self.action(args)
basic_cli/parser.py ADDED
@@ -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,9 @@
1
+ basic_cli/__init__.py,sha256=r1G5sH6sgZgSR574M2u5XgWlsyMTiUZ0RUl3CA7d5dY,20
2
+ basic_cli/arguments.py,sha256=wpWHmX80Fv-LtGlCFb_gPS-Ws4UfNzdaoLcHyN2RcDg,557
3
+ basic_cli/command.py,sha256=wJa8zffZLfxOMwsSzirNH-Yqq8UC-XKiSKxyFP5rC5E,201
4
+ basic_cli/parser.py,sha256=qgc_xEd0dmnxmRd8Con30ESAkun-xJ-GYz9XGlV13qU,1004
5
+ basic_cli/text_manager.py,sha256=Y6_o__PTBNgAQDlIskJ5sPtYSWlTWHiq0eeHOKVqNhg,462
6
+ basic_cli_builder-0.1.0.dist-info/METADATA,sha256=KHrbz1ZQbrjIMnAhRJz6aBB6iqLGyepmiZB8VXx_Wf4,280
7
+ basic_cli_builder-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ basic_cli_builder-0.1.0.dist-info/top_level.txt,sha256=AkykIW72OSKeKsn6g4EuPrFRkwqceQQ-2u8WjtHuIiQ,10
9
+ basic_cli_builder-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ basic_cli