bundle

command module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2018 License: MIT Imports: 11 Imported by: 0

README

bundle

Bundle merges multiple Go source files into single one.

Install

go get -u github.com/bbrodriges/bundle

Usage

As a separate command:

$ bundle --help
Usage: bundle -p <package_name> [-d] pattern...
Available options:
  -d	Delete source files after bundling
  -p string
    	Package name to be written into result file. Required

$ bundle -d -p main *_gen.go > bundle.go # bundle all autogenerated files in current folder
$ bundle -d -p main -o bundle.go user.msgp.go user.str.go # bundle only specific files

As a go generate flag:

package types

//go:generate msgp -o=user.msgp.go -tests=false -io=false
//go:generate stringer -type=User -output=user.str.go -linecomment
//msgp:shim UserState as:string using:(UserState).String/UserStateFromString

//go:generate bundle -d -p=types -o=user_gen.go user.msgp.go user.str.go

type User struct {
    Username string `msg:"username"`
    Email string `msg:"email"`
    State UserState `msg:"state"`
}

type UserState int

const (
    Unknown UserState = iota -1 // UNKNOWN
    Inactive                    // INACTIVE
    Active                      // ACTIVE
    Banned                      // BANNED
)

func UserStateFromString(s string) UserState {
    switch s {
    case "INACTIVE":
        return Inactive
    case "ACTIVE":
        return Active
    case "BANNED":
        return Banned
    }
    return Unknown
}

The above code upon calling go generate . will:

  1. create files called user.msgp.go and user.str.go with containing autogenerated code
  2. bundle these two files into single user_gen.go and delete source files user.msgp.go and user.str.go

Limitations

  • bundle cannot handle definition conflicts (e.g. structs, functions, constants of the same names)
  • bundle cannot handle import cicle conflicts

All it does is collects and strips out import declarations from every given source files AST and concats them into single file with helping comments.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL