Plis
Plis API contains a set of useful objects and functions that help you interact with the user and run other plis tools.
Plis API
- flags :
Object
- Is an object with all the flags specified in the tool config. - args :
Object
- Is an object with all the arguments specified in the tool config. - help:
Function
- When called it will display the help text of the tool (the help text is auto-generated by plis) - forceOverride:
Function
- Can enable/disable force override of files. - runPlisTool:
Function
- Is used to run other plis tools within your tool.
plis.flags
This object will give you access to all the flags that you specified in the tool configurations, all the flags are properties of the flags
object.
The flags values are set by user input or by the default property in the tool configurations, if there is no default and no user input for the flag the flag will get the default value of its type
- string - The default of a string type flag will be an empty string
""
- int - The default of an int type will be
0
- float - The default of a float type will be
0.0
- bool- The default of a bool type will be
false
How to use flags
var p = require("plis")
function main(){
// Get flags
var flags = p.flags;
console.log(flags.myFlag)
}
local p = require("plis")
function main()
-- Get the flags
flags = p.flags
print(flags.myFlag)
end
plis.args
This object will give you access to all the arguments that you specified in the tool configurations, all the arguments are properties of the args
object.
The arguments values are set by user input or by the default property in the tool configurations, if there is no default and no user input for the argument the flag will get the default value of its type.
- string - The default of a string type flag will be an empty string
""
- int - The default of an int type will be
0
- float - The default of a float type will be
0.0
- bool- The default of a bool type will be
false
How to use arguments
var p = require("plis")
function main(){
// Get arguments
var args = p.arguments
console.log(args.myArg)
}
local p = require("plis")
function main()
-- Get the arguments
args = p.args
print(args.myArg)
end
plis.help()
Plis help will display the tool help, this is the same as running plis {tool-name} --help
How to use help()
var p = require("plis")
function main(){
p.help()
}
local p = require("plis")
function main()
p.help()
end
plis.forceOverride(b bool)
Plis by default does not allow overriding files that already exist and it will ask the user if they want to override this files, if you want to disable this behavior you can do this by using forceOverride
How to use forceOverride()
var p = require("plis")
function main(){
// Enable force override
p.forceOverride(true)
// Disable force override
p.forceOverride(false)
}
local p = require("plis")
function main()
-- Enable force override
p.forceOverride(true)
-- Disable force override
p.forceOverride(false)
end
plis.runPlisTool(name string, args []string)
Plis allows you to run other plis tools, this is useful if you want to build upon an existing tool. If your tool depends on another tool don't forget to add that tool as a dependency by running plis get {tool-repo}
inside the tool folder, this will create a plis.json
that will have your tool dependencies.
How to use runPlisTool()
This example shows how you could use plis-tool inside your tool.
var p = require("plis")
function main(){
// Same as running `plis tool new myNewTool -t lua`
p.runPlisTool("tool",["new","myNewTool","-t","lua"])
}
local p = require("plis")
function main()
-- Same as running `plis tool new myNewTool -t lua`
p.runPlisTool("tool",{"new","myNewTool","-t","lua"})
end
Updated almost 8 years ago