The fun init
command is a subcommand of Funcraft, which can be used to specify application templates.
You can use common templates provided by Function Compute or custom templates to create
applications with efficiency. This topic describes how to run the fun init
command to experience and develop an application with efficiency.
Overview
fun init
command: fun init --help
The following result is returned:Usage: fun init [options] [template]
Initialize a new project based on a template. A template can be a folder containing template metadata and boilerplate files, a name of a pre-built template, or a url that resolves to a template. You can find more information about template at https://yq.aliyun.com/articles/674364.
Options:
-o, --output-dir [path] Where to output the initialized app into (default: ".")
-n, --name [name] The name of your project to be generated as a folder (default: "")
-m, --merge [merge] Merge into the template.[yml|yaml] file if it already exist (default: false)
--no-input Disable prompting and accept default values defined template config
-V, --var [vars] Template variable
-h, --help display help for command
Examples:
$ fun init
$ fun init event-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
Options that can be added to the fun init command
Option | Default value | Required | Description | Example |
---|---|---|---|---|
-o, --output-dir | . | No | The directory where the initialized application is to be stored. |
|
-n, --name | fun-app | No | The name of the folder where the application resides. |
|
-m, --merge | false | No | Specifies whether to merge the current content into the YAML file. |
|
--no-input | N/A | No | Disables prompts and uses 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 template variables. |
|
-V, --var | N/A | No | The variables in the template. The template may contain multiple template variables.
When you initialize the template, if you need to specify values for some variables,
you are prompted to set the variables. You can set the variables in one of the following
ways:
Note 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 (=).
|
|
-h, --help | N/A | No | Displays the help information of the fun init command. |
|
Obtain application templates
- Templates provided by Function Compute, including offline and online templates
- Directly use the offline templates that are integrated into Funcraft.
- Specify the name of an online template. Then, Funcraft converts the name to the GitHub address of the template.
- Git or Mercurial repository templates: Obtain application templates from the corresponding repository.
- Templates stored in the on-premises file system: Obtain application templates from the on-premises file system.
- Custom templates: Obtain uploaded custom templates from GitHub.
Obtain offline templates provided by Function Compute
Obtain online templates provided by Function Compute
Online templates provided by Function Compute are stored in GitHub.
Run the fun init <templates name>
command to obtain the online application template.
Obtain Git or Mercurial repository templates
user/repo
format. You can use the following templates:
fun init foo/bar
fun init fun init gh:foo/bar/bar
fun initfun init gl:foo/barfoo/bar
fun init fun init bb:foo/bar/bar
fun fun init github:foo/barfoo/bar
fun fun init gitlab:foo/barfoo/bar
fun fun init bitbucket:foo/barfoo/bar
fun ifun init git+ssh://git@github.com/foo/bar.gitnit foo/bar
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
Obtain on-premises templates
Obtain a custom template
If the existing templates cannot meet your requirements, you can customize a template and upload it to GitHub. When you or others need to use the template, you can obtain the template from GitHub.