-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring to insert the package sub-command
- Loading branch information
1 parent
077a661
commit f1a5417
Showing
3 changed files
with
100 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Run a command line helper for various Fyne tools. | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"path" | ||
"strings" | ||
|
||
"github.com/fyne-io/fyne" | ||
) | ||
|
||
func writeResource(file, name string) { | ||
bytes, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
fmt.Println("Unable to load file " + file) | ||
return | ||
} | ||
|
||
res := fyne.NewStaticResource(path.Base(file), bytes) | ||
|
||
fmt.Printf("var %s = %#v\n", name, res) | ||
} | ||
|
||
func writeHeader(pkg string) { | ||
fmt.Println("package", pkg) | ||
fmt.Println() | ||
fmt.Println("import \"github.com/fyne-io/fyne\"") | ||
} | ||
|
||
func sanitiseName(file string) string { | ||
name := strings.Replace(file, ".", "-", -1) | ||
name = strings.Replace(name, " ", "", -1) | ||
|
||
return strings.ToLower(name) | ||
} | ||
|
||
// Bundle takes a file (at filepath) and serialises it into Go to be output into | ||
// a generated bundle file. The go file will be part of the specified package | ||
// (pkg) and the data will be assigned to variable named "name". If you are | ||
// appending an existing resource file then pass true to noheader as the headers | ||
// should only be output once per file. | ||
func Bundle(name, pkg string, noheader bool, filepath string) { | ||
if !noheader { | ||
writeHeader(pkg) | ||
} | ||
fmt.Println() | ||
|
||
if name == "" { | ||
name = sanitiseName(path.Base(filepath)) | ||
} | ||
writeResource(filepath, name) | ||
} | ||
|
||
var name, pkg string | ||
var noheader bool | ||
|
||
func bundleFlags() { | ||
flag.StringVar(&name, "name", "", "The variable name to assign the serialised resource") | ||
flag.StringVar(&pkg, "package", "main", "The package to output in headers (if not appending)") | ||
flag.BoolVar(&noheader, "append", false, "Append an existing go file (don't output headers)") | ||
} | ||
|
||
func bundleRun(args []string) { | ||
if len(args) != 1 { | ||
fmt.Println("Missing required file parameter after flags") | ||
return | ||
} | ||
|
||
Bundle(name, pkg, noheader, args[0]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func packageFlags() { | ||
|
||
} | ||
|
||
func packageRun(_ []string) { | ||
fmt.Println("TODO implement packager") | ||
} |