beego bee tool mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

536 lines
17 KiB

8 years ago
8 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
1 month ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. bee
  2. ===
  3. Bee is a command-line tool facilitating development of Beego-based application.
  4. [![Build Status](https://img.shields.io/travis/beego/bee.svg?branch=master&label=master)](https://travis-ci.org/beego/bee)
  5. [![Build Status](https://img.shields.io/travis/beego/bee.svg?branch=develop&label=develop)](https://travis-ci.org/beego/bee)
  6. ## Requirements
  7. - Go version >= 1.12
  8. ## Installation
  9. To install `bee` use the `go get` command:
  10. ```bash
  11. go get github.com/beego/bee/v2
  12. ```
  13. Then you can add `bee` binary to PATH environment variable in your `~/.bashrc` or `~/.bash_profile` file:
  14. ```bash
  15. export PATH=$PATH:<your_main_gopath>/bin
  16. ```
  17. > If you already have `bee` installed, updating `bee` is simple:
  18. ```bash
  19. go get -u github.com/beego/bee/v2
  20. ```
  21. ## Basic commands
  22. Bee provides a variety of commands which can be helpful at various stages of development. The top level commands include:
  23. ```
  24. version Prints the current Bee version
  25. migrate Runs database migrations
  26. api Creates a Beego API application
  27. bale Transforms non-Go files to Go source files
  28. fix Fixes your application by making it compatible with newer versions of Beego
  29. dlv Start a debugging session using Delve
  30. dockerize Generates a Dockerfile for your Beego application
  31. generate Source code generator
  32. hprose Creates an RPC application based on Hprose and Beego frameworks
  33. new Creates a Beego application
  34. pack Compresses a Beego application into a single file
  35. rs Run customized scripts
  36. run Run the application by starting a local development server
  37. ```
  38. ### bee version
  39. To display the current version of `bee`, `beego` and `go` installed on your machine:
  40. ```bash
  41. $ bee version
  42. ______
  43. | ___ \
  44. | |_/ / ___ ___
  45. | ___ \ / _ \ / _ \
  46. | |_/ /| __/| __/
  47. \____/ \___| \___| v1.6.2
  48. ├── Beego : 1.7.2
  49. ├── GoVersion : go1.7.4
  50. ├── GOOS : linux
  51. ├── GOARCH : amd64
  52. ├── NumCPU : 2
  53. ├── GOPATH : /home/beeuser/.go
  54. ├── GOROOT : /usr/lib/go
  55. ├── Compiler : gc
  56. └── Date : Monday, 26 Dec 2016
  57. ```
  58. You can also change the output format using `-o` flag:
  59. ```bash
  60. $ bee version -o json
  61. {
  62. "GoVersion": "go1.7.4",
  63. "GOOS": "linux",
  64. "GOARCH": "amd64",
  65. "NumCPU": 2,
  66. "GOPATH": "/home/beeuser/.go",
  67. "GOROOT": "/usr/lib/go",
  68. "Compiler": "gc",
  69. "BeeVersion": "1.6.2",
  70. "BeegoVersion": "1.7.2"
  71. }
  72. ```
  73. For more information on the usage, run `bee help version`.
  74. ### bee new
  75. To create a new Beego web application:
  76. ```bash
  77. $ bee new my-web-app
  78. ______
  79. | ___ \
  80. | |_/ / ___ ___
  81. | ___ \ / _ \ / _ \
  82. | |_/ /| __/| __/
  83. \____/ \___| \___| v1.6.2
  84. 2016/12/26 22:28:11 INFO ▶ 0001 Creating application...
  85. create /home/beeuser/.go/src/github.com/user/my-web-app/
  86. create /home/beeuser/.go/src/github.com/user/my-web-app/conf/
  87. create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/
  88. create /home/beeuser/.go/src/github.com/user/my-web-app/models/
  89. create /home/beeuser/.go/src/github.com/user/my-web-app/routers/
  90. create /home/beeuser/.go/src/github.com/user/my-web-app/tests/
  91. create /home/beeuser/.go/src/github.com/user/my-web-app/static/
  92. create /home/beeuser/.go/src/github.com/user/my-web-app/static/js/
  93. create /home/beeuser/.go/src/github.com/user/my-web-app/static/css/
  94. create /home/beeuser/.go/src/github.com/user/my-web-app/static/img/
  95. create /home/beeuser/.go/src/github.com/user/my-web-app/views/
  96. create /home/beeuser/.go/src/github.com/user/my-web-app/conf/app.conf
  97. create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/default.go
  98. create /home/beeuser/.go/src/github.com/user/my-web-app/views/index.tpl
  99. create /home/beeuser/.go/src/github.com/user/my-web-app/routers/router.go
  100. create /home/beeuser/.go/src/github.com/user/my-web-app/tests/default_test.go
  101. create /home/beeuser/.go/src/github.com/user/my-web-app/main.go
  102. 2016/12/26 22:28:11 SUCCESS ▶ 0002 New application successfully created!
  103. ```
  104. For more information on the usage, run `bee help new`.
  105. ### bee run
  106. To run the application we just created, you can navigate to the application folder and execute:
  107. ```bash
  108. $ cd my-web-app && bee run
  109. ```
  110. Or from anywhere in your machine:
  111. ```
  112. $ bee run github.com/user/my-web-app
  113. ```
  114. For more information on the usage, run `bee help run`.
  115. ### bee pack
  116. To compress a Beego application into a single deployable file:
  117. ```bash
  118. $ bee pack
  119. ______
  120. | ___ \
  121. | |_/ / ___ ___
  122. | ___ \ / _ \ / _ \
  123. | |_/ /| __/| __/
  124. \____/ \___| \___| v1.6.2
  125. 2016/12/26 22:29:29 INFO ▶ 0001 Packaging application on '/home/beeuser/.go/src/github.com/user/my-web-app'...
  126. 2016/12/26 22:29:29 INFO ▶ 0002 Building application...
  127. 2016/12/26 22:29:29 INFO ▶ 0003 Using: GOOS=linux GOARCH=amd64
  128. 2016/12/26 22:29:31 SUCCESS ▶ 0004 Build Successful!
  129. 2016/12/26 22:29:31 INFO ▶ 0005 Writing to output: /home/beeuser/.go/src/github.com/user/my-web-app/my-web-app.tar.gz
  130. 2016/12/26 22:29:31 INFO ▶ 0006 Excluding relpath prefix: .
  131. 2016/12/26 22:29:31 INFO ▶ 0007 Excluding relpath suffix: .go:.DS_Store:.tmp
  132. 2016/12/26 22:29:32 SUCCESS ▶ 0008 Application packed!
  133. ```
  134. For more information on the usage, run `bee help pack`.
  135. ### bee rs
  136. Inspired by makefile / npm scripts.
  137. Run script allows you to run arbitrary commands using Bee.
  138. Custom commands are provided from the "scripts" object inside bee.json or Beefile.
  139. To run a custom command, use: $ bee rs mycmd ARGS
  140. ```bash
  141. $ bee help rs
  142. USAGE
  143. bee rs
  144. DESCRIPTION
  145. Run script allows you to run arbitrary commands using Bee.
  146. Custom commands are provided from the "scripts" object inside bee.json or Beefile.
  147. To run a custom command, use: $ bee rs mycmd ARGS
  148. AVAILABLE SCRIPTS
  149. gtest
  150. APP_ENV=test APP_CONF_PATH=$(pwd)/conf go test -v -cover
  151. gtestall
  152. APP_ENV=test APP_CONF_PATH=$(pwd)/conf go test -v -cover $(go list ./... | grep -v /vendor/)
  153. ```
  154. *Run your scripts with:*
  155. ```$ bee rs gtest tests/*.go```
  156. ```$ bee rs gtestall```
  157. ### bee api
  158. To create a Beego API application:
  159. ```bash
  160. $ bee api my-api
  161. ______
  162. | ___ \
  163. | |_/ / ___ ___
  164. | ___ \ / _ \ / _ \
  165. | |_/ /| __/| __/
  166. \____/ \___| \___| v1.6.2
  167. 2016/12/26 22:30:12 INFO ▶ 0001 Creating API...
  168. create /home/beeuser/.go/src/github.com/user/my-api
  169. create /home/beeuser/.go/src/github.com/user/my-api/conf
  170. create /home/beeuser/.go/src/github.com/user/my-api/controllers
  171. create /home/beeuser/.go/src/github.com/user/my-api/tests
  172. create /home/beeuser/.go/src/github.com/user/my-api/conf/app.conf
  173. create /home/beeuser/.go/src/github.com/user/my-api/models
  174. create /home/beeuser/.go/src/github.com/user/my-api/routers/
  175. create /home/beeuser/.go/src/github.com/user/my-api/controllers/object.go
  176. create /home/beeuser/.go/src/github.com/user/my-api/controllers/user.go
  177. create /home/beeuser/.go/src/github.com/user/my-api/tests/default_test.go
  178. create /home/beeuser/.go/src/github.com/user/my-api/routers/router.go
  179. create /home/beeuser/.go/src/github.com/user/my-api/models/object.go
  180. create /home/beeuser/.go/src/github.com/user/my-api/models/user.go
  181. create /home/beeuser/.go/src/github.com/user/my-api/main.go
  182. 2016/12/26 22:30:12 SUCCESS ▶ 0002 New API successfully created!
  183. ```
  184. For more information on the usage, run `bee help api`.
  185. ### bee hprose
  186. To create an Hprose RPC application based on Beego:
  187. ```bash
  188. $ bee hprose my-rpc-app
  189. ______
  190. | ___ \
  191. | |_/ / ___ ___
  192. | ___ \ / _ \ / _ \
  193. | |_/ /| __/| __/
  194. \____/ \___| \___| v1.6.2
  195. 2016/12/26 22:30:58 INFO ▶ 0001 Creating application...
  196. create /home/beeuser/.go/src/github.com/user/my-rpc-app/
  197. create /home/beeuser/.go/src/github.com/user/my-rpc-app/conf/
  198. create /home/beeuser/.go/src/github.com/user/my-rpc-app/controllers/
  199. create /home/beeuser/.go/src/github.com/user/my-rpc-app/models/
  200. create /home/beeuser/.go/src/github.com/user/my-rpc-app/routers/
  201. create /home/beeuser/.go/src/github.com/user/my-rpc-app/tests/
  202. create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/
  203. create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/js/
  204. create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/css/
  205. create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/img/
  206. create /home/beeuser/.go/src/github.com/user/my-rpc-app/views/
  207. create /home/beeuser/.go/src/github.com/user/my-rpc-app/conf/app.conf
  208. create /home/beeuser/.go/src/github.com/user/my-rpc-app/controllers/default.go
  209. create /home/beeuser/.go/src/github.com/user/my-rpc-app/views/index.tpl
  210. create /home/beeuser/.go/src/github.com/user/my-rpc-app/routers/router.go
  211. create /home/beeuser/.go/src/github.com/user/my-rpc-app/tests/default_test.go
  212. create /home/beeuser/.go/src/github.com/user/my-rpc-app/main.go
  213. 2016/12/26 22:30:58 SUCCESS ▶ 0002 New application successfully created!
  214. ```
  215. For more information on the usage, run `bee help hprose`.
  216. ### bee bale
  217. To pack all the static files into Go source files:
  218. ```bash
  219. $ bee bale
  220. ______
  221. | ___ \
  222. | |_/ / ___ ___
  223. | ___ \ / _ \ / _ \
  224. | |_/ /| __/| __/
  225. \____/ \___| \___| v1.6.2
  226. 2016/12/26 22:32:41 INFO ▶ 0001 Loading configuration from 'bee.json'...
  227. 2016/12/26 22:32:41 SUCCESS ▶ 0002 Baled resources successfully!
  228. ```
  229. For more information on the usage, run `bee help bale`.
  230. ### bee migrate
  231. For database migrations, use `bee migrate`.
  232. For more information on the usage, run `bee help migrate`.
  233. ### bee generate
  234. Bee also comes with a source code generator which speeds up the development.
  235. For example, to generate a new controller named `hello`:
  236. ```bash
  237. $ bee generate controller hello
  238. ______
  239. | ___ \
  240. | |_/ / ___ ___
  241. | ___ \ / _ \ / _ \
  242. | |_/ /| __/| __/
  243. \____/ \___| \___| v1.6.2
  244. 2016/12/26 22:33:58 INFO ▶ 0001 Using 'Hello' as controller name
  245. 2016/12/26 22:33:58 INFO ▶ 0002 Using 'controllers' as package name
  246. create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/hello.go
  247. 2016/12/26 22:33:58 SUCCESS ▶ 0003 Controller successfully generated!
  248. ```
  249. For more information on the usage, run `bee help generate`.
  250. ### bee dockerize
  251. Bee also helps you dockerize your Beego application by generating a Dockerfile.
  252. For example, to generate a Dockerfile with `Go version 1.6.4` and exposing port `9000`:
  253. ```bash
  254. $ bee dockerize -image="library/golang:1.6.4" -expose=9000
  255. ______
  256. | ___ \
  257. | |_/ / ___ ___
  258. | ___ \ / _ \ / _ \
  259. | |_/ /| __/| __/
  260. \____/ \___| \___| v1.6.2
  261. 2016/12/26 22:34:54 INFO ▶ 0001 Generating Dockerfile...
  262. 2016/12/26 22:34:54 SUCCESS ▶ 0002 Dockerfile generated.
  263. ```
  264. For more information on the usage, run `bee help dockerize`.
  265. ### bee dlv
  266. Bee can also help with debugging your application. To start a debugging session:
  267. ```bash
  268. ______
  269. | ___ \
  270. | |_/ / ___ ___
  271. | ___ \ / _ \ / _ \
  272. | |_/ /| __/| __/
  273. \____/ \___| \___| v1.8.0
  274. 2017/03/22 11:17:05 INFO ▶ 0001 Starting Delve Debugger...
  275. Type 'help' for list of commands.
  276. (dlv) break main.main
  277. Breakpoint 1 set at 0x40100f for main.main() ./main.go:8
  278. (dlv) continue
  279. > main.main() ./main.go:8 (hits goroutine(1):1 total:1) (PC: 0x40100f)
  280. 3: import (
  281. 4: _ "github.com/user/myapp/routers"
  282. 5: beego "github.com/beego/beego/v2/server/web"
  283. 6: )
  284. 7:
  285. => 8: func main() {
  286. 9: beego.Run()
  287. 10: }
  288. 11:
  289. ```
  290. For more information on the usage, run `bee help dlv`.
  291. ## Shortcuts
  292. Because you'll likely type these generator commands over and over, it makes sense to create aliases:
  293. ```bash
  294. # Generator Stuff
  295. alias g:a="bee generate appcode"
  296. alias g:m="bee generate model"
  297. alias g:c="bee generate controller"
  298. alias g:v="bee generate view"
  299. alias g:mi="bee generate migration"
  300. ```
  301. These can be stored , for example, in your `~/.bash_profile` or `~/.bashrc` files.
  302. ## Help
  303. To print more information on the usage of a particular command, use `bee help <command>`.
  304. For instance, to get more information about the `run` command:
  305. ```bash
  306. $ bee help run
  307. USAGE
  308. bee run [appname] [watchall] [-main=*.go] [-downdoc=true] [-gendoc=true] [-vendor=true] [-e=folderToExclude] [-tags=goBuildTags] [-runmode=BEEGO_RUNMODE]
  309. OPTIONS
  310. -downdoc
  311. Enable auto-download of the swagger file if it does not exist.
  312. -e=[]
  313. List of paths to exclude.
  314. -gendoc
  315. Enable auto-generate the docs.
  316. -main=[]
  317. Specify main go files.
  318. -runmode
  319. Set the Beego run mode.
  320. -tags
  321. Set the build tags. See: https://golang.org/pkg/go/build/
  322. -vendor=false
  323. Enable watch vendor folder.
  324. DESCRIPTION
  325. Run command will supervise the filesystem of the application for any changes, and recompile/restart it.
  326. ```
  327. ## Contributing
  328. Bug reports, feature requests and pull requests are always welcome.
  329. We work on two branches: `master` for stable, released code and `develop`, a development branch.
  330. It might be important to distinguish them when you are reading the commit history searching for a feature or a bugfix,
  331. or when you are unsure of where to base your work from when contributing.
  332. ### Found a bug?
  333. Please [submit an issue][new-issue] on GitHub and we will follow up.
  334. Even better, we would appreciate a [Pull Request][new-pr] with a fix for it!
  335. - If the bug was found in a release, it is best to base your work on `master` and submit your PR against it.
  336. - If the bug was found on `develop` (the development branch), base your work on `develop` and submit your PR against it.
  337. Please follow the [Pull Request Guidelines][new-pr].
  338. ### Want a feature?
  339. Feel free to request a feature by [submitting an issue][new-issue] on GitHub and open the discussion.
  340. If you'd like to implement a new feature, please consider opening an issue first to talk about it.
  341. It may be that somebody is already working on it, or that there are particular issues that you should be aware of
  342. before implementing the change. If you are about to open a Pull Request, please make sure to follow the [submissions guidelines][new-pr].
  343. ## Submission Guidelines
  344. ### Submitting an issue
  345. Before you submit an issue, search the archive, maybe you will find that a similar one already exists.
  346. If you are submitting an issue for a bug, please include the following:
  347. - An overview of the issue
  348. - Your use case (why is this a bug for you?)
  349. - The version of `bee` you are running (include the output of `bee version`)
  350. - Steps to reproduce the issue
  351. - Eventually, logs from your application.
  352. - Ideally, a suggested fix
  353. The more information you give us, the more able to help we will be!
  354. ### Submitting a Pull Request
  355. - First of all, make sure to base your work on the `develop` branch (the development branch):
  356. ```
  357. # a bugfix branch for develop would be prefixed by fix/
  358. # a bugfix branch for master would be prefixed by hotfix/
  359. $ git checkout -b feature/my-feature develop
  360. ```
  361. - Please create commits containing **related changes**. For example, two different bugfixes should produce two separate commits.
  362. A feature should be made of commits splitted by **logical chunks** (no half-done changes). Use your best judgement as to
  363. how many commits your changes require.
  364. - Write insightful and descriptive commit messages. It lets us and future contributors quickly understand your changes
  365. without having to read your changes. Please provide a summary in the first line (50-72 characters) and eventually,
  366. go to greater lengths in your message's body. A good example can be found in [Angular commit message format](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit-message-format).
  367. - Please **include the appropriate test cases** for your patch.
  368. - Make sure all tests pass before submitting your changes.
  369. - Rebase your commits. It may be that new commits have been introduced on `develop`.
  370. Rebasing will update your branch with the most recent code and make your changes easier to review:
  371. ```
  372. $ git fetch
  373. $ git rebase origin/develop
  374. ```
  375. - Push your changes:
  376. ```
  377. $ git push origin -u feature/my-feature
  378. ```
  379. - Open a pull request against the `develop` branch.
  380. - If we suggest changes:
  381. - Please make the required updates (after discussion if any)
  382. - Only create new commits if it makes sense. Generally, you will want to amend your latest commit or rebase your branch after the new changes:
  383. ```
  384. $ git rebase -i develop
  385. # choose which commits to edit and perform the updates
  386. ```
  387. - Re-run the tests
  388. - Force push to your branch:
  389. ```
  390. $ git push origin feature/my-feature -f
  391. ```
  392. [new-issue]: #submitting-an-issue
  393. [new-pr]: #submitting-a-pull-request
  394. ## Licence
  395. ```text
  396. Copyright 2016 bee authors
  397. Licensed under the Apache License, Version 2.0 (the "License");
  398. you may not use this file except in compliance with the License.
  399. You may obtain a copy of the License at
  400. http://www.apache.org/licenses/LICENSE-2.0
  401. Unless required by applicable law or agreed to in writing, software
  402. distributed under the License is distributed on an "AS IS" BASIS,
  403. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  404. See the License for the specific language governing permissions and
  405. limitations under the License.
  406. ```