Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

adding CLI function to my code.

Hey there,I'm new to programming. I'm working on this project and I want to add to it slash commands (e.g /help /show etc.).Any ideas on how to do it?Any help would be very appreciated.
Look about raw_input() function I hope it will help you :)
(Oct 29, 2018 01:19 PM)Meedman Wrote:  Look about raw_input() function I hope it will help you :)

I'll check it out later bud.Thanks for helping me.
There's surprisingly no great utility for this. The go-to most people use is the "cmd" package. It's simple and it's built into the standard library. But it's not super intuitive or particularly well-documented. There are better tutorials on blogs and stuff than there are on the docs.python.org page.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
well there's either an object-oriented way to pursue it where you view everything like a parser and lexer would, parse it initially, tokenize it, separate operands, determine types, detect strings, etc.; a more than-usual advanced parser, but worth it in the end.

i have some code-based resources (which probably aren't useful if you're at the degree of python i assume you are), but good luck:

parsing strings
parsing general tokens
parsing octal/hex/denary-based integers
Contact for professional programming services.
unazed#5906
I think I have an idea what you mean, check this out and tell me if it's what you were going for.

Code
# User input asking for a command
user = input('type in command > ')

#example of a help menu
help_menu = '''
example
help
menu

'''

#if the user types in /help then print out the help menu
if user == "/help":
print (help_menu)


I think this is what you're trying to do? Let me know if I'm mistaken
argparse might help -- you can add something such as...

test.py -arg1 value -arg2 value

etc
(Oct 29, 2018 03:25 PM)Goodies Wrote:  There's surprisingly no great utility for this. The go-to most people use is the "cmd" package. It's simple and it's built into the standard library. But it's not super intuitive or particularly well-documented. There are better tutorials on blogs and stuff than there are on the docs.python.org page.

thanks for your feedback bud.Will consider this.


(Oct 29, 2018 06:34 PM)Infamia Wrote:  well there's either an object-oriented way to pursue it where you view everything like a parser and lexer would, parse it initially, tokenize it, separate operands, determine types, detect strings, etc.; a more than-usual advanced parser, but worth it in the end.

i have some code-based resources (which probably aren't useful if you're at the degree of python i assume you are), but good luck:

parsing strings
parsing general tokens
parsing octal/hex/denary-based integers

thanks for your help.I believe argparse is what I waas looking for.
(Oct 30, 2018 10:08 AM)dv989 Wrote:  argparse might help -- you can add something such as...

test.py -arg1 value -arg2 value

etc

Thank you mate, I almost lost all hope after reading someone say "there is no nice way" or something like that lmao

This is python, almost everything has a built-in way

User argparse and sys libs, get the args from sys.argv
If you are using python 2.x then cmd module is good. If you are on 3 then use cmd2.

I am actually in a huge project now that I am using cmd2 and argparser. It is very nice and works pretty dang good. If you run into any problems let me know.
(Oct 30, 2018 06:41 PM)Keat Wrote:  If you are using python 2.x then cmd module is good. If you are on 3 then use cmd2.

I am actually in a huge project now that I am using cmd2 and argparser. It is very nice and works pretty dang good. If you run into any problems let me know.

ofc buddy,thanks for your help.


(Oct 30, 2018 01:13 PM)dontspamthisplease Wrote:  Thank you mate, I almost lost all hope after reading someone say "there is no nice way" or something like that lmao

This is python, almost everything has a built-in way

User argparse and sys libs, get the args from sys.argv

thats what i thought,thanks.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by HackersNov 11, 2025 09:42 AM 0 206 Nov 11, 2025 09:42 AM
Last Post: Hackers
by HackersDec 11, 2024 05:11 PM 21 535 Dec 11, 2024 05:11 PM
Last Post: padrino
by HackersDec 11, 2024 08:31 AM 23 695 Dec 11, 2024 08:31 AM
Last Post: Hackers