General operations
This topic describes the general commands for fcli.
Prerequisites
Run fcli shell in the directory that contains the executable file to enter interactive mode.
Change directory (cd)
Use the cd command to navigate the entity hierarchy of Function Compute, not to switch local directories.
>>> cd serviceName // Go to the directory of the serviceName service.
>>> ls // In the service directory, run ls to list all functions in the serviceName service.
>>> cd functionName // Go to the directory of the functionName function.
>>> ls // In the function directory, run ls to list all triggers in the functionName function.List resources in the current directory (ls)
-l int32or--limit int32: Specifies the maximum number of resources to list. The default value is 100.-t stringor--next-token string: Lists resources starting from the specified NextToken.-p stringor--prefix string: Lists resources with the specified prefix.-k stringor--start-key string: Lists resources starting from the specified resource.
>>> cd myService
>>> ls
aFunction
bFunction
cFunction
cFuncion2
dFunction
eFunction
>>> ls -l 4 // List a maximum of 4 files.
aFunction
bFunction
cFunction
cFuncion2
NextToken: dFunction
>>> ls -t dFunction // List files starting from the NextToken (dFunction).
dFunction
eFunction
>>> ls -p c // List files with the prefix c.
cFunction
cFunction2
>>> ls -k dFunction // List files whose names start from dFunction.
dFunction
eFunction View the current directory (pwd)
Use the pwd command to view the current directory.
View resource details (info)
Use the info command to view the details of a Function Compute resource. The parameter can be a service name, function name, or trigger name.
>>> info <your serviceName> // View the details of this service.
>>> info <your functionName> // View the details of this function.
>>> info <your triggerName> // View the details of this trigger.Configure fcli (config)
Use the config command to modify the configuration in config.yaml.
>>> config --access-key-id 12345678 // Change the access-key-id to 12345678. Delete a resource (rm)
rm: Deletes a resource.NoteBefore you use this command, make sure that the target function has no triggers and the target service has no functions.
-for--forced: Deletes the resource without prompting for confirmation.
>>> rm myFunction
Do you want to remove the resource /fc/myService/myFunction [y/n]: // Confirmation is required before deletion.
>>> rm -f myFunction // Deletes the resource directly without confirmation.Sandbox environment (sbox)
fcli provides a local sandbox environment that is consistent with the function runtime environment in Function Compute. In the sandbox, you can install third-party dependency libraries and perform local tests.
-d stringor--code-dir string: Specifies the code directory. This directory is mounted to the /code path in the sandbox environment.-t stringor--runtime string: Specifies the runtime environment.
>>> sbox -d code -t nodejs6 // Install dependencies in the code directory. The language is Node.js 6.
Entering the container. Your code is in the /code directory.
root@df9fc****:/code# npm init -f // Node.js 6 requires a package.json file to be generated.
npm info it worked if it ends with ok
npm info using npm@3.10.10
npm info using node@v6.10.3
npm WARN using --force I sure hope you know what you are doing.
Wrote to /code/package.json:
{
"name": "code",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"jimp": "^0.2.28"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
npm info init written successfully
npm info ok
root@df9fc****:/code# npm install jimp // Install the jimp dependency library.
npm info it worked if it ends with ok
...
npm info lifecycle jimp@0.2.28~postinstall: jimp@0.2.28
code@1.0.0 /code
-- jimp@0.2.28
npm WARN code@1.0.0 No description
npm WARN code@1.0.0 No repository field.
npm info ok
root@df9fc****:/code# exit // Exit the sbox environment. Get help (help)
Use the help command to display help information.
help: Lists all commands.[command] --help: Lists all parameters for the specified command.For example,
ls --help.
Clear the screen (clear)
Use the clear command to clear the screen.
Exit fcli (exit)
Use the exit command to exit the fcli tool.