sm_get_cli
Documentation languages
| pt_BR | en_US - this file | zh_CN |
|---|
A community-maintained fork of the GetX™ CLI for building Flutter and Server applications. The upstream project is jonataslaw/get_cli; fork-specific behavior is summarized below.
Installation
Install the published package from pub.dev:
dart pub global activate sm_get_cli
Ensure the pub cache bin directory is on PATH. The package installs both get and getx executables:
get --version
getx --version
Git and local path activation are supported for development builds:
dart pub global activate --source git https://github.com/sm-packages/sm_get_cli.git
dart pub global activate --source path .
When migrating from get_cli, keep the existing get/getx commands, get_cli: configuration key, and .get_cli.yaml file. Only the Dart package and activation name change to sm_get_cli.
Fork capability index
| Capability | User contract |
|---|---|
| Independent package and compatible commands | Published as sm_get_cli; keeps get, getx, get_cli:, and .get_cli.yaml. All supported activation sources report the package version. |
| Configurable GetX package prefix | get_package_prefix: sm_getx generates package:sm_getx/get.dart; any compatible GetX package can be selected, and the default remains get. |
| State generation and GetX 4/5 output | get create state and use_state generate and connect state files; version selects compatible binding output. |
| Project-defined templates | Explicit template files or a .template directory can replace page, controller, binding, state, and insertion templates. |
| Configurable locale generation | Input and output can be configured or overridden with command flags; file name and class name are set through configuration. |
| Nested route generation | get create page:name on parent adds child routes and avoids duplicate routes, pages, and imports. |
| Safe Flutter project creation | Current Flutter Android language options and paths containing spaces are passed as structured arguments; failed creation stops initialization. |
| Reliable failure status | Handled CLI failures leave a nonzero process exit code for scripts and CI. |
| Current Dart and Flutter compatibility | The fork tracks current Dart formatting and process APIs without changing the generated-code contract. |
Fork configuration
Place these keys under get_cli: in pubspec.yaml, or at the top level of .get_cli.yaml. When both files define fork settings, the pubspec.yaml get_cli: map takes precedence.
get_cli:
# Defaults to GetX 4 generation behavior.
version: 5
# Defaults to false. Page, screen, and controller generation also creates state.
use_state: true
# Defaults to get. Use the package name of your GetX fork.
get_package_prefix: sm_getx
templates:
# Discovers non-recursive *.template files by filename.
path: assets/templates
# Explicit keys take precedence over discovered files.
# page: assets/templates/page.dart.template
# controller: assets/templates/controller.dart.template
# binding: assets/templates/binding.dart.template
# state: assets/templates/state.dart.template
# insert_state: assets/templates/insert_state.dart.template
# insert_controller: assets/templates/insert_controller.dart.template
locales:
input: translations
output: lib/gen
file_name: locales
class_name: AppTranslation
version defaults to 4, and use_state defaults to false. Run get create state:session on home to create a state explicitly and connect it to a matching controller. For templates, page falls back to view, and missing custom templates fall back to the built-in samples.
get_package_prefix defaults to get. Set it to the package name of any compatible GetX fork, such as sm_getx, and built-in Flutter generators plus the @{import} custom-template variable will emit import 'package:sm_getx/get.dart';. The value must be a valid lowercase Dart package name; invalid values stop the command with a configuration error. The project must already depend on the configured package; this setting does not add, remove, or change dependencies. Get Server projects continue to import package:get_server/get_server.dart.
Locale generation reads only JSON files. Explicit -i and -o arguments override configuration; the default input is assets/locales, the default generated filename is locales.g.dart, and the default translation class is AppTranslation:
get generate locales -i translations -o lib/gen
Translation keys are emitted verbatim as Dart field names, so use valid, non-keyword Dart identifiers such as welcome_message. Invalid JSON fails generation. The current key validator rejects leading digits, whitespace, and several special characters, but it does not normalize or fully validate Dart identifiers.
Runtime and compatibility contracts
- Repeating top-level or nested page generation must not duplicate route constants,
GetPageentries, child routes, or imports. - Flutter project creation supports Kotlin or Java for Android. The removed Flutter iOS-language option is not passed, and a nonzero
flutter createresult stops the remaining initialization. - Caught CLI exceptions leave a nonzero process exit code. Automation may treat exit code
0as success and any nonzero code as failure. - Toolchain compatibility is automatic. Projects only need to satisfy the SDK constraint in
pubspec.yaml; no separate compatibility setting is required.
Command quick reference
// To create a flutter project in the current directory:
// Note: By default it will take the folder's name as project name
// You can name the project with `get create project:my_project`
// If the name has spaces use `get create project:"my cool project"`
get create project
// To generate the chosen structure on an existing project:
get init
// To create a page:
// (Pages have controller, view, and binding)
// Note: you can use any name, ex: `get create page:login`
// Nota: use this option if the chosen structure was Getx_pattern
get create page:home
// To create a screen
// (Screens have controller, view, and binding)
// Note: you can use any name, ex: `get screen page:login`
// Nota: use this option if the chosen structure was CLEAN (by Arktekko)
get create screen:home
// To create a new controller in a specific folder:
// Note: you don't need to reference the folder,
// Getx will search automatically for the home folder
// and add your controller there.
get create controller:dialogcontroller on home
// To create a state and connect it to a matching controller:
get create state:session on home
// To create a new view in a specific folder:
// Note: you don't need to reference the folder,
// Getx will automatically search for the home folder
// and insert your view there.
get create view:dialogview on home
// To create a new provider in a specific folder:
get create provider:user on home
// To generate a localization file:
// Note: 'assets/locales' directory with your translation files in json format
get generate locales assets/locales
// To generate a class model:
// Note: 'assets/models/user.json' path of your template file in json format
// Note: on == folder output file
// Getx will automatically search for the home folder
// and insert your class model there.
get generate model on home with assets/models/user.json
//to generate the model without the provider
get generate model on home with assets/models/user.json --skipProvider
//Note: the URL must return a json format
get generate model on home from "https://api.github.com/users/CpdnCristiano"
// To install a package in your project (dependencies):
get install camera
// To install several packages from your project:
get install http path camera
// To install a package with specific version:
get install path:1.6.4
// You can also specify several packages with version numbers
// To install a dev package in your project (dependencies_dev):
get install flutter_launcher_icons --dev
// To remove a package from your project:
get remove http
// To remove several packages from your project:
get remove http path
// To update CLI:
get update
// or `get upgrade`
// Shows the current CLI version:
get -v
// or `get --version`
// For help
get help
Exploring the CLI
let's explore the existing commands in the cli
Create project
get create project
Using to generate a new project, you can choose between Flutter and get_server, after creating the default directory, it will run a get init next command
Init
get init
Use this command with care it will overwrite all files in the lib folder. It allows you to choose between two structures, getx_pattern and clean.
Create page
get create page:name
this command allows you to create modules, it is recommended for users who chose to use getx_pattern.
creates the view, controller and binding files, in addition to automatically adding the route.
You can create a module within another module.
get create page:name on other_module
When creating a new project now and use on to create a page the CLI will use children pages.
Create Screen
get create screen:name
similar to the create page, but suitable for those who use Clean
Create controller
get create controller:dialog on your_folder
create a controller in a specific folder.
Using with option You can now create a template file, the way you prefer.
run
get create controller:auth with examples/authcontroller.dart on your_folder
or with url run
get create controller:auth with 'https://raw.githubusercontent.com/sm-packages/sm_get_cli/master/samples_file/controller.dart.template' on your_folder
input:
@{import}
class @{controller} extends GetxController {
final email = ''.obs;
final password = ''.obs;
void login() {
}
}
output:
import 'package:get/get.dart';
class AuthController extends GetxController {
final email = ''.obs;
final password = ''.obs;
void login() {}
}
Create view
get create view:dialog on your_folder
create a view in a specific folder
Generate Locates
create the json language files in the assets/locales folder.
input:
pt_BR.json
{
"buttons": {
"login": "Entrar",
"sign_in": "Cadastrar-se",
"logout": "Sair",
"sign_in_fb": "Entrar com o Facebook",
"sign_in_google": "Entrar com o Google",
"sign_in_apple": "Entrar com a Apple"
}
}
en_US.json
{
"buttons": {
"login": "Login",
"sign_in": "Sign-in",
"logout": "Logout",
"sign_in_fb": "Sign-in with Facebook",
"sign_in_google": "Sign-in with Google",
"sign_in_apple": "Sign-in with Apple"
}
}
Run :
get generate locales assets/locales
output:
abstract class AppTranslation {
static Map<String, Map<String, String>> translations = {
'en_US' : Locales.en_US,
'pt_BR' : Locales.pt_BR,
};
}
abstract class LocaleKeys {
static const buttons_login = 'buttons_login';
static const buttons_sign_in = 'buttons_sign_in';
static const buttons_logout = 'buttons_logout';
static const buttons_sign_in_fb = 'buttons_sign_in_fb';
static const buttons_sign_in_google = 'buttons_sign_in_google';
static const buttons_sign_in_apple = 'buttons_sign_in_apple';
}
abstract class Locales {
static const en_US = {
'buttons_login': 'Login',
'buttons_sign_in': 'Sign-in',
'buttons_logout': 'Logout',
'buttons_sign_in_fb': 'Sign-in with Facebook',
'buttons_sign_in_google': 'Sign-in with Google',
'buttons_sign_in_apple': 'Sign-in with Apple',
};
static const pt_BR = {
'buttons_login': 'Entrar',
'buttons_sign_in': 'Cadastrar-se',
'buttons_logout': 'Sair',
'buttons_sign_in_fb': 'Entrar com o Facebook',
'buttons_sign_in_google': 'Entrar com o Google',
'buttons_sign_in_apple': 'Entrar com a Apple',
};
}
now just add the line in GetMaterialApp
GetMaterialApp(
...
translationsKeys: AppTranslation.translations,
...
)
Generate model example
Create the json model file in the assets/models/user.json
input:
{
"name": "",
"age": 0,
"friends": ["", ""]
}
Run :
get generate model on home with assets/models/user.json
output:
class User {
String name;
int age;
List<String> friends;
User({this.name, this.age, this.friends});
User.fromJson(Map<String, dynamic> json) {
name = json['name'];
age = json['age'];
friends = json['friends'].cast<String>();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['name'] = this.name;
data['age'] = this.age;
data['friends'] = this.friends;
return data;
}
}
Separator file type
One day a user asked me, if it was possible to change what the final name of the file was, he found it more readable to use: my_controller_name.controller.dart, instead of the default generated by the cli: my_controller_name_controller. dart thinking about users like him we added the option for you to choose your own separator, just add this information in your pubsepc.yaml
Example:
get_cli:
separator: "."
Configure Getx directory layout
When you create a page or screen, each module will have bindings, controllers, views sub directories.
If you prefer to have a flat file hierarchy, add the following lines to your pubspec.yaml:
get_cli:
sub_folder: false
Are your imports disorganized?
To help you organize your imports a new command was created: get sort, in addition to organizing your imports the command will also format your dart file. thanks to dart_style.
When using get sort all files are renamed, with the separator.
To not rename use the --skipRename flag.
You are one of those who prefer to use relative imports instead of project imports, use the --relative option. sm_get_cli will convert.
Internationalization of the cli
CLI now has an internationalization system.
to translate the cli into your language:
- create a new json file with your language, in the translations folder
- Copy the keys from the file, and translate the values
- send your PR.
TODO:
- Support for customModels
- Include unit tests
- Improve generated structure
- Add a backup system
Libraries
- cli_config/cli_config
- commands/commands_list
- commands/impl/args_mixin
- commands/impl/commads_export
- commands/impl/create/controller/controller
- commands/impl/create/create
- commands/impl/create/page/page
- commands/impl/create/project/project
- commands/impl/create/provider/provider
- commands/impl/create/screen/screen
- commands/impl/create/state/state
- commands/impl/create/view/view
- commands/impl/generate/generate
- commands/impl/generate/locales/locales
- commands/impl/generate/model/model
- commands/impl/help/help
- commands/impl/init/flutter/init
- commands/impl/init/flutter/init_getxpattern
- commands/impl/init/flutter/init_katteko
- commands/impl/init/get_server/get_server_command
- commands/impl/install/install
- commands/impl/install/install_get
- commands/impl/remove/remove
- commands/impl/sort/sort
- commands/impl/update/update
- commands/impl/version/version
- commands/interface/command
- common/utils/backup/backup_utils
- common/utils/json_serialize/helpers
- common/utils/json_serialize/json_ast/error
- common/utils/json_serialize/json_ast/json_ast
- common/utils/json_serialize/json_ast/location
- common/utils/json_serialize/json_ast/parse
- common/utils/json_serialize/json_ast/parse_error_types
- common/utils/json_serialize/json_ast/tokenize
- common/utils/json_serialize/json_ast/tokenize_error_types
- common/utils/json_serialize/json_ast/utils/grapheme_splitter
- common/utils/json_serialize/json_ast/utils/substring
- common/utils/json_serialize/model_generator
- common/utils/json_serialize/sintaxe
- common/utils/logger/log_utils
- common/utils/pub_dev/pub_dev_api
- common/utils/pubspec/package_version
- common/utils/pubspec/pubspec_lock
- common/utils/pubspec/pubspec_utils
- common/utils/pubspec/yaml_to.string
- common/utils/shell/shel.utils
- core/generator
- core/internationalization
- core/locales.g
- core/structure
- exception_handler/exception_handler
- exception_handler/exceptions/cli_exception
- extensions
- extensions/dart_code
- extensions/list
- extensions/string
- functions/binding/add_dependencies
- functions/binding/find_bindings
- functions/controller/add_states
- functions/controller/find_controllers
- functions/create/create_list_directory
- functions/create/create_main
- functions/create/create_single_file
- functions/create/create_web
- functions/exports_files/add_export
- functions/find_file/find_file_by_name
- functions/find_file/find_folder_by_directory
- functions/formatter_dart_file/frommatter_dart_file
- functions/is_url/is_url
- functions/path/replace_to_relative
- functions/replace_vars/replace_vars
- functions/routes/arc_add_route
- functions/routes/get_add_route
- functions/routes/get_app_pages
- functions/routes/get_support_children
- functions/sorter_imports/sort
- functions/version/check_dev_version
- functions/version/print_get_cli
- functions/version/version_update
- get_cli
- models/file_model
- samples/impl/analysis_options
- samples/impl/arctekko/arc_main
- samples/impl/arctekko/arc_routes
- samples/impl/arctekko/arc_screen
- samples/impl/arctekko/config_example
- samples/impl/generate_locales
- samples/impl/get_app_pages
- samples/impl/get_binding
- samples/impl/get_controller
- samples/impl/get_provider
- samples/impl/get_route
- samples/impl/get_server/pubspec
- samples/impl/get_state
- samples/impl/get_view
- samples/impl/getx_pattern/get_main
- samples/interface/sample_interface
- sm_get_cli