fun init is a subcommand of Fun. fun init allows you to create Function Compute applications based on templates to simplify Function Compute usage and development. Function Compute provides several commonly used templates. You can also build your own custom templates.
Syntax
$ fun init --help
Usage: init [options] [location]
Initializes a new fun project
Options:
-o, --output-dir [outputDir] where to output the initialized app into (default: .)
-n, --name [name] name of your project to be generated as a folder (default: fun-app)
--no-input [noInput] disable prompting and accept default values defined template config
-V, --var [vars] template variable
-h, --help output usage information
Examples:
$ fun init
$ fun init helloworld-nodejs8
$ fun init foo/bar
$ fun init gh:foo/bar
$ fun init gl:foo/bar
$ fun init bb:foo/bar
$ fun init github:foo/bar
$ fun init gitlab:foo/bar
$ fun init bitbucket:foo/bar
$ fun init git+ssh://git@github.com/foo/bar.git
$ fun init hg+ssh://hg@bitbucket.org/bar/foo
$ fun init git@github.com:foo/bar.git
$ fun init https://github.com/foo/bar.git
$ fun init /path/foo/bar
$ fun init -n fun-app -V foo=bar /path/foo/bar
Option description
Option | Default value | Description |
---|---|---|
-o, —output-dir | . |
Optional. Specifies the directory where the initialized application will be stored. |
-n, —name | fun-app |
Optional. Specifies the name of your project to be generated as a folder. |
—no-input | false |
Optional. Disables prompts and accepts default values for template variables. |
-V, —var | empty | Optional. Specifies a template variable value. |
-h, —help | null | Optional. Displays the usage information of fun init. |
Example:
The
-o,--output-dir
option specifies the directory where the initialized application will be stored. By default, the application will be stored in the directory wherefun init
is running.$fun init -o /path/foo/bar
The
-n,--name
option specifies the name of your project to be generated as a folder. Default value:fun-app
.$fun init -n xxx
The
-V,--var
option allows you to specify values for template variables. A template contains multiple template variables. Most variables have configured default values, but some variables require you to specify a value when the template is being initialized. You can enter a value or press Enter to use the default value. You can also use the-V,--var
option to specify variable values. You do not need to specify the values again after you have used this option to specify them. You must enter a key-value pair for this option. The key can contain letters, digits, and underscores (_). The value can contain all characters. Separate a key and a value with an equal sign (=).$fun init -V foo=bar -V bar=baz
The
--no-input
option is used to disable prompts and accept default values for template variables. If you do not want to receive the input prompts of template variables, you can use this option to disable prompts and use default values for variables.$fun init --no-input
Template location
Function Compute provides the following templates:
- Official templates, including offline and online templates:
- Offline templates are integrated in Fun.
- Online templates require you to specify the name of a template. Fun will convert the name to the GitHub address of the template.
- Git or Mercurial repository templates. The supported abbreviation method is described in the following section.
- Templates stored in the local file system.
To use a custom template, you can submit your custom template to GitHub, and then run fun init
to specify the GitHub address of the template.
Example:
To use an official template, you can use the
fun init
command and select a template as prompted. You do not need to enter the full name of a template to perform a search. If you are not sure which kind of template you need, thefun init
command without options provides official templates for you to select as prompted.$fun init
? Select a tempalte to init (Use arrow keys or type to search)
helloworld-nodejs8
helloworld-nodejs6
helloworld-python3
helloworld-python2.7
helloworld-java8
helloworld-php7.2
The official template helloworld-nodejs8 is integrated in Fun and can be used offline. This template generates a Node.js 8 Function Compute application that displays the phrase “Hello World”. Many commonly used templates are listed as official templates. You can use a template by specifying the name rather than the entire template repository address.
$fun init helloworld-nodejs8
Git or Mercurial repository templates support multiple prefix abbreviation methods. Addresses of repository templates in GitHub can be written in the
user/repo
format.$ fun init foo/bar
$ fun init gh:foo/bar
$ fun init gl:foo/bar
$ fun init bb:foo/bar
$ fun init github:foo/bar
$ fun init gitlab:foo/bar
$ fun init bitbucket:foo/bar
$ fun init git+ssh://git@github.com/foo/bar.git
$ fun init hg+ssh://hg@bitbucket.org/bar/foo
$ fun init git@github.com:foo/bar.git
$ fun init https://github.com/foo/bar.git
Note: You must install the corresponding version control tool.
To use a template stored in the local file system, you can clone an online template to the local file system and specify the template path to initialize the template offline.
$ fun init /path/foo/bar
Summary
fun init simplifies your Function Compute usage and development. You can also upload and share your customized Function Compute templates.