-
Notifications
You must be signed in to change notification settings - Fork 1
How do I add a command to PercOS?
To add a command to PercOS you will need some knowledge of python 3. In any case, adding a command to PercOS is really simple.
First you will need to create a file where your command is going to reside. It's better to name the file in the same way as the command, so in our case we're going to make a command that responds to what the user asks, like a virtual assistant. For that reason we're going to name the file assistant.py
. We need the .py
to say that it is a python file, that makes PercOS know that it can read it.
For adding the class which is going to house the command we'll need to import the base command class, which has all the things a command needs so that if you forget to add something to your command (it's very unlikely) PercOS wont give out an error. To import that class you only will need to add from command import Command
. Then you'll need to add the class, in our case class Assistant(Command):
, the '(Command)' is there to say that this class inherits the properties of the Command class.
This is really simple, a command has 3 predefined properties (they all are strings):
- Name called
name
, we'll sayname = "assistant"
so that when the users type inassistant
they'll get our command - Description called
desc
, we'll saydesc = "this command starts the assistant"
so that the help message shows this - Author called
author
, in my case I'll sayauthor = "ThePerkinrex"
And it also has 1 function: -
call(self, args=None)
whereself
is your command class,self.dire
is a custom class that stores the current directory in PercOS's filesystem (self.dire.dir
), the real directory where it is now (self.dire.realdir
) and the base directory where all the filesystem is located (self.dire.bd
) (PercOS_filesystem/
by default). In the command objectself.usr
is a string with the name of the current user, andargs
is an optional argument which passes what the user did put after the command. We'll write a print statement so that we see how it works. Additionaly you can add theusage
variable, wich tells the usage command how your command works. This is just a string like this:usage='assistant [question]'
So, your class should look something like this:
from command import Command
class Assistant(Command):
name = "assistant"
desc = "This command starts the assistant"
author = "ThePerkinrex"
usage = "assistant [question]"
def call(self, dire, usr, args=None):
print("this is my assistant")
For more info check out the command API
PercOS wiki v1.1