Taitava / obsidian-shellcommands

Execute system commands via hotkeys or command palette in Obsidian (https://obsidian.md). Some automated events are also supported, and execution via URI links.
GNU General Public License v3.0
365 stars 12 forks source link

Internal: Support multiple parameters for variables #43

Closed Taitava closed 3 years ago

Taitava commented 3 years ago

Current rules for {{variable}} parameters:

Terminology

An argument is a value that a user passes to a variable to control its behavior. A variable receives an argument as a parameter.

Support multiple parameters

Make a variable able to define parameters like this:

protected readonly parameters: IParameters = {
    parameter_name1: {
        type: "string",
        required: true,
    },
    parameter_name2: {
        type: "integer",
        required: false,
    },
    parameter_name3: {
        options: ["static", "value", "options"],
        required: false,
    },
};

protected arguments: {
    parameter_name1: string,
    parameter_name2: number,
    parameter_name3: string,
};

parameter_name1, parameter_name2 and parameter_name3 are internal names for the parameters that are not exposed to users.

A user would write multiple arguments like this: {{variable:argument text:5:static}}, so : works as a separator between arguments. Note that argument text is a single argument, the space is just a normal character.

parameter_name3 is a parameter that can only take predefined values, so the value must be one of: static, value or options.

Support optional parameters

Parameters can be defined optional by setting required to false. Optional parameters can be located after or before mandatory parameters, maybe even in between (but this is untested!).

Taitava commented 3 years ago

Done.

Taitava commented 2 years ago

For some reason this issue was not added into a milestone even though the issue is done already. I added it to 0.6.0, which is a version where this was released in.