fast.cli
an incredible command line interface for flutter. it allows you to create your own cli without coding a line.
with this cli, you can create your custom templates and define how your project will start.
the generated directories and files are defined from the outside in, that is, the users define the resources, the cli generates for you.
you can easily:
- create
- use
- edit
- share
do not hesitate to share the plugins created by you with the community, it is very simple.
features
- templates generator
- aplication scaffold generator
- snippet generator for visual studio code
- custom commands
- standard line commands (some commands already included in the cli)
- install (add a package to the project dependencies)
install
first of all it is necessary to install the package and configure cache location.
install this package globally
to do this, you must have the dart sdk installed and configured
see the guide referring to the installation of packages globally if you have any doubts on how to do it.
$ pub global activate fast
configure cache location
add the fast cache to your path environment variable.
$home/.fastcli/bin/
overview
- plugin system – provide the mechanism for you to import a set of templates, resources and custom commands.
- custom commands – commands defined by you to be executed in cmd.
- scaffold – an initial structural for a project(start your project with a structure already defined)
- template – (code that will be created for your project, as if it were a snippet, but by command line)
quick start
quick use of cli features.
install your first plugin
the plugin system is the way in which you can create, use and share your own resources. think of them as plugins for vs code, but in this case for a cli.
to use the cli it is necessary to install at least one plugin, so install your first plugin with the command below.
don’t worry, just below you will learn how to create your own plugin. for now just install this plugin already created.
fast plugin add <repository that has a plugin>
example:
$ fast plugin add git https://github.com/pbissonho/mvc_git_test.git
see what the plugin provides
after installing the plugin, an executable is created with his name, so run the command below to test.
use the “mvc” plugin that was installed directly from the repository.
this command will display the functionalities that the plugin provides.
$ mvc --help
use a plugin scaffold
<plugin_name> create --name <flutter_projet_name> --scaffold <_scaffold_name>
create a flutter application called “myapp” with the structure defined in the “sample” scaffold of the “mvc” plugin
example:
$ mvc create --name myapp --scaffold sample
run a plugin custom command
mvc run <custom_command_name>
example:
$ mvc run build
use a plugin template
mvc <template_name> <template_arg1> <template_arg2> <template_arg3>...
$ mvc page --name mypage
plugin system
the plugin system is the way in which you can create, use and share your own resources. think of them as plugins for vs code, but in this case for a cli.
this cli is intended to provide the tool for you to create your own cli, by default the cli comes with no resources, that is, it does not have any available plugin, command or scaffold. so to use it is necessary to install at least one plugin.
no vs code os plugins can provide snippets, themes, icons and other things.
in this cli the plugins provide:
- commands
- scaffolds
- templates
structure of a plugin:
scaffolds/ <- folder to add the scaffols.
templates/ <- folder to add the templates.
commands.yaml <- file to define custom commands
plugin.yaml <- file to define the name and description of the plugin.
see an example on github clicking here..
using a plugin
fisrt instal the plugin. you can install directly from a repository.
when adding a plugin an executable is created with the name of the plugin, so after installing it it is possible to use it by the plugin’s own name.
install:
$ fast plugin add git https://github.com/pbissonho/mvc_git_test.git
use:
$ mvc --help
plugin commands
add
add a plugin
it is possible to add a plugin directly from a github repository or some local path.
install directly from a repository.
$ fast plugin add git https://github.com/pbissonho/mvc_git_test.git
install from a local path.
$ fast plugin add path home/mypath/
remove
removes a plugin.
$ fast plugin remove --name <plugin_name>
list
show all installed plugins.
$ fast plugin list
scaffold
a scaffold is a yaml file where you can define a folder structure and a set of dependencies for a flutter project.
instead of creating a blank flutter project, you can start the project with a folder structure already created and the dependencies configured.
define a scaffold.yaml
to define your scaffold just follow the example below:
file: scaffold.yaml
# the scaffold name.
name: sample
description: a sample scaffold.
author: pedro bissonho <[email protected]>
# the folder structure that will be generated inside the 'lib' folder.
structure:
- ui:
- pages
- shared
- themes
- data:
- models
- repositorys
- blocs
# the folder structure that will be generated inside the 'test' folder.
test_structure:
- ui:
- data:
- fixtures:
# the standard dependencies that the project will have.
# your project will start with all these dependencies.
# if the version is not informed, the version will be configured as the last version available in dart pub.
dependencies:
koin:
flutter_bloc:
# the standard dev_dependencies that the project will have.
# if the version is not informed, the version will be configured as the last version available in dart pub.
dev_dependencies:
koin_test:
use a scaffold
add your scaffold.yaml file inside a plugin and then use it.
<plugin_name> create --name <app_name> --scaffold <scaffold_name>
example:
$ mvc create --name myapp --scaffold mvc1
result
when starting your project with the sample scaffold you will have that project as a result.
template
templates are files or a set of files that you use to generate code. generate code as snippests, but by command line.
define a template
first we define the files that are generated.
in this example, the ‘@name’ tag will be replaced by the ‘–name’ argument when the file is generated.
file: @name_page.dart
import 'package:flutter/material.dart';
class @namepage extends statefulwidget {
@override
[email protected] createstate() => [email protected]();
}
class [email protected] extends state<@namepage> {
@override
widget build(buildcontext context) {
return scaffold(
body: container(
child: text("hello"),
),
);
}
}
in the same folder as the file above we have the yaml file that defines how the template should be created.
file: template.yaml
#yaml file for configuring the template.
#the template name
name: page
#the template description
description: create_flutter_page.
#path where files should be sent
to: lib/ui/pages/@name
#arguments to be passed when executing this template
# you can define as many arguments as you want.
args:
- name
# - other1
# - other2
# - other3
using a template
run this command so that your template is generated.
<plugin_name> <template_name> <templates_arg1, templates_arg2, templates_arg3...>
example:
$ mvc page --name home
result
you will now have the following file in the path lib/ui/pages/home
import 'package:flutter/material.dart';
class homepage extends statefulwidget {
@override
_homepagestate createstate() => _homepagestate();
}
class _homepagestate extends state<homepage> {
@override
widget build(buildcontext context) {
return scaffold(
body: container(
child: text("hello"),
),
);
}
}
snippets generator
a command to generate snippets for the vc code based on the template files.
reuse the code inserted in the template files to generate snippets for visual studio code.
define your snippets
first we create the template file and template.yaml.
and then set a snippe to be generated.
file: @name_page.dart
import 'package:flutter/material.dart';
class @namepage extends statefulwidget {
@override
[email protected] createstate() => [email protected]();
}
class [email protected] extends state<@namepage> {
@override
widget build(buildcontext context) {
return scaffold(
body: container(
child: text("hello"),
),
);
}
}
file: template.yaml
name: page
description: create_flutter_page.
to: lib/ui/pages/@name
# you can define as many arguments as you want.
args:
- name
# set up a list of snippests.
snippets:
# the file containing the snippet code to be generated
# reuse the code inserted in one of the template files to generate a vc code snippets.
- file: '@name_page.dart'
prefix: page
#file lines that will not be included in the snippet.
excluded:
- 0
- 1
# it is possible to create snippests for each template file.
# - file: '@name_other1.dart'
# prefix: other1
# excluded:
# - 0
# - file: '@name_other2.dart'
# prefix: other2
# excluded:
# - 0
generate snippests
snippests are generated only for the called plugin, so
if i had more snippes installed they will not be generated for them.
run the command below to generate the snippets.
<plugin_name> snippets
example:
$ mvc snippets
result
it will be possible to use the generated snippet.
custom commands
recording and having to write commands like ‘flutter build runner build’ it’s not a cool thing to do.
,so the custom commands will solve this problem. write only once and then use them for an alias.
you only need to create a commands.yaml file in your pluginand define your commands.
define your commands
file: commands.yaml
commands:
runner: flutter build runner build
push: git push origin master
mkdir: mkdir myfolder
running a command
<plugin_name> run <command_name>
example:
$ mvc run runner
migrating
v0.3 to v0.4
the commands “config template”,’config scaffolds’ and ‘config commands’ have been removed. it is now much easier to configure the cli and start using it. just create your plugin and install it.
the scaffolds, templates and commands remain exactly the same, so you will use version 0.4 without making any changes, just add them to your plugin.
Comments are closed.