Revel Command line tool source reading

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

This article for a detailed look at the Revel command-line tool. Here are a few files for this package, along with the corresponding feature descriptions.

Filename Brief description (short) Full Description (Long)
Clean.go Clean a Revel application ' s temp files The Revel Web application named by the given import path.
For example:
Revel Clean Github.com/robfig/revel/samples/chat
It removes the app/tmp directory.
New.go Create a Skeleton Revel application New creates a few files to get a new Revel application running quickly.
It puts all of the files on the given import path, taking the final element in
The path to is the app name.
For example:
Revel New Import/path/helloworld
Package.go Package a Revel application (e.g. for deployment) The Revel Web application named by the given import path.
This allows is deployed and run on a machine, that lacks a Go installation.
For example:
Revel Package Github.com/robfig/revel/samples/chat
Run.go Run a Revel application Run the Revel Web application named by the given import path.
For example, to run the Chat Hostel sample application:
Revel Run Github.com/robfig/revel/samples/chat Dev
The run mode is used to select which set of app.conf configuration should
Apply and May is used to determine logic in the application itself.
Run mode defaults to "Dev".
You can set a port as an optional third parameter. For
Revel Run Github.com/robfig/revel/samples/chat prod 8080
Test.go Run all tests from the command-line Run all tests to the Revel app named by the given import path.
For example, to run the booking sample application ' s tests:
Revel Test Github.com/robfig/revel/samples/booking Dev
The run mode is used to select which set of app.conf configuration should
Apply and May is used to determine logic in the application itself.
Run mode defaults to "Dev".

The above files correspond to several commands for the command line tool, while the remaining files and their functions are as follows:

Filename Role
Package_run.bat.template Run script templates under Windows
Package_run.sh.template Running script templates under Linux
Rev.go Main functions and command parsing, running
Util.go Tool Function Collection

We need to first understand the following code snippet in the Rev.go file:

Cribbed from the genius organization of the "Go" command.
Type Command struct {
Run func (args []string)
Usageline, short, Long string
}

Func (cmd *command) Name () string {
Name: = cmd. Usageline
I: = strings. Index (Name, "")
If I >= 0 {
name = Name[:i]
}
return name
}

var commands = []*command{
Cmdrun,
Cmdnew,
Cmdclean,
Cmdpackage,
Cmdtest,
}

    1. The command structure is simple, run uses the handler function that stores the command, and the other three parameters are used to store the form of the command, a simple description, and a complete description. For example:
      var cmdnew = &command{
      Usageline: "New [path]",
      Short: "Create a skeleton Revel application",
      Long:
      New creates a few files to get a new Revel application running quickly.

      It puts all of the files in the given import path, taking the final element in
      the path to be the app name.

      For example:

      revel new import/path/helloworld
      ,
      }

    2. The name function reads the command name from Usageline, for example: Run,new, and so on.
    3. Commands is an array of *command types that stores *command for all commands, such as cmdnew, which is defined in the New.go file, noting that the value of the run variable in the structure is obtained in the INIT function, for example:

      Func init () {
      Cmdnew.run = Newapp
      }
      Func Newapp (args []string) {
      ...
      }

When we use a command like: Revel New MyApp, the main function in the Rev package is called, parses the arguments, and then calls the run function of the corresponding command, and the code snippet is as follows:

For _, cmd: = range Commands {
If Cmd. Name () = = Args[0] {
Cmd. Run (args[1:])
Return
}
}

The rest of the details in the

Rev.go are relatively simple, and are not explained on a line-by-row basis.
This article is here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.