rust web 框架 loco 命令大全

更新日期: 2024-05-05 阅读次数: 916 字数: 325 分类: rust

loco 框架的命令非常强大,完全可以媲美 laravel。

常用命令

  • 新建项目: loco new
  • 启动服务:cargo loco start
  • 查看所有路由:cargo loco routes

主要命令

> cargo loco

Finished dev [unoptimized + debuginfo] target(s) in 16.27s
Running `target/debug/loco_tool-cli`
The one-person framework for Rust

Usage: loco_tool-cli [OPTIONS] <COMMAND>

Commands:
  start     Start an app
  db        Perform DB operations
  routes    Describe all application endpoints
  task      Run a custom task
  generate  code generation creates a set of files and code templates based on a predefined set of rules
  doctor    Validate and diagnose configurations
  version   Display the app version
  help      Print this message or the help of the given subcommand(s)

Options:
  -e, --environment <ENVIRONMENT>  Specify the environment [default: development]
  -h, --help                       Print help
  -V, --version                    Print version

自动生成代码相关

loco 最强大的部分是能自动生成 model,controller 等的模板代码。

> cargo loco help generate

Finished dev [unoptimized + debuginfo] target(s) in 1.28s
Running `target/debug/loco_tool-cli help generate`
code generation creates a set of files and code templates based on a predefined set of rules

Usage: loco_tool-cli generate [OPTIONS] <COMMAND>

Commands:
  model       Generates a new model file for defining the data structure of your application, and test file logic
  migration   Generates a new migration file
  scaffold    Generates a CRUD scaffold, model and controller
  controller  Generate a new controller with the given controller name, and test file
  task        Generate a Task based on the given name
  worker      Generate worker
  mailer      Generate mailer
  deployment  Generate a deployment infrastructure
  help        Print this message or the help of the given subcommand(s)

Options:
  -e, --environment <ENVIRONMENT>  Specify the environment [default: development]
  -h, --help                       Print help
  -V, --version                    Print version

参考

  • https://loco.rs/docs/the-app/models/

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式

tags: loco