github.com/liquid-dev/text@v0.3.3-liquid/cmd/gotext/common.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "go/build" 10 "go/parser" 11 12 "github.com/liquid-dev/tools/go/loader" 13 ) 14 15 const ( 16 extractFile = "extracted.gotext.json" 17 outFile = "out.gotext.json" 18 gotextSuffix = ".gotext.json" 19 ) 20 21 // NOTE: The command line tool already prefixes with "gotext:". 22 var ( 23 wrap = func(err error, msg string) error { 24 if err == nil { 25 return nil 26 } 27 return fmt.Errorf("%s: %v", msg, err) 28 } 29 errorf = fmt.Errorf 30 ) 31 32 // TODO: still used. Remove when possible. 33 func loadPackages(conf *loader.Config, args []string) (*loader.Program, error) { 34 if len(args) == 0 { 35 args = []string{"."} 36 } 37 38 conf.Build = &build.Default 39 conf.ParserMode = parser.ParseComments 40 41 // Use the initial packages from the command line. 42 args, err := conf.FromArgs(args, false) 43 if err != nil { 44 return nil, wrap(err, "loading packages failed") 45 } 46 47 // Load, parse and type-check the whole program. 48 return conf.Load() 49 }