export-funcmap

command module
v0.0.0-...-5ea1423 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2017 License: BSD-3-Clause Imports: 4 Imported by: 0

README

export-funcmap

Export a funcmap variable declaration to

  • its symbolic version
  • its public identifiers, when possible

The output is useful to perform source code analysis of go templates, it will be similar to this,

package gen

var export = map[string]interface {}
{
  "and": func(arg0 interface {}, args ...interface {}) interface {} {
  	return nil
  },
  "call": func(fn interface {}, args ...interface {}) (interface {}, error) {
  	return nil, nil
  },
  "html": func(args ...interface {}) string {
   return ""
  },
}
var exportPublic []map[string]string = []map[string]string{
  map[string]string{
    "FuncName": "html",
    "Sel": "template.HTMLEscaper",
    "Pkg": "text/template",
  },
}

Install

go get -u github.com/mh-cbon/export-funcmap

Cli

export-funcmap - 0.0.0
Export a funcmap variable declaration to its symbolic version.

Usage

	export-funcmap <outfilename> <outpackage> <outvarname> <pkgpath:var...>....

	outfilename
		The output filepath of the export result.
		required.

	outpackage
		The output package name of the export result.
		required.

	outvarname
		The output variable name of the export result.
		required.

	pkgpath:var...
		A repeatable argument of package path (for example html/template),
		followed by at least one semi-colon to indicate the desired variable
		to export.
		Each package path can be followed by multiple semi-colon variable if
		multiple variable needs to be extracted from the same package.
		required.

	-v
		Show version

	-h|--help
		Show help

Example
	export-funcmap gen.go gen export text/template:builtins
	export-funcmap gen.go gen export text/template:builtins:builtins
	export-funcmap gen.go gen export text/template:builtins text/template:builtins

Usage

package main

import(
  "github.com/mh-cbon/export-funcmap/export"
)

func main () {
  targets := []string{
    "text/template:builtins",
    "text/template:builtins",
  }
  outfilename := "gen.go"
  outpackage := "gen"
  outvarname := "funcsMap"

  file, err := export.Export(targets, outfilename, outpackage, outvarname)
  if err != nil {
  	panic(err)
  }

  // print the result.
  export.PrintAstFile(os.Stdout, file)
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
a
b
d

Jump to

Keyboard shortcuts

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