Skip to content

Commit

Permalink
fix warn, use xcode script args
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-stripe committed Oct 9, 2015
1 parent 6d22f38 commit 39b12e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
31 changes: 19 additions & 12 deletions resourceful.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func parseFolder(filepath string) (EnumType, error) {

func main() {
app := cli.NewApp()
l := log.New(os.Stderr, "", 0)
app.Name = "resourceful"
app.Usage = "Add strong typing to imageNamed: in Swift apps"
app.Flags = []cli.Flag{
Expand All @@ -68,13 +69,28 @@ func main() {
Usage: "The destination file for generated Swift code",
EnvVar: "SCRIPT_OUTPUT_FILE_0",
},
cli.BoolFlag{
Name: "warn, w",
}
app.Commands = []cli.Command{
{
Name: "warn",
Usage: "Generate xcode warnings for usage of imageNamed",
Flags: []cli.Flag{
cli.StringFlag{
Name: "warndirectory, w",
Usage: "The directory to search for legacy usage of imageNamed",
EnvVar: "SRCROOT",
},
},
Action: func(c *cli.Context) {
err := warn(c.String("warndirectory"))
if err != nil {
l.Println("Error detecting warnings.")
os.Exit(1)
}
},
},
}
app.Action = func(c *cli.Context) {
l := log.New(os.Stderr, "", 0)
enumType, err := parseFolder(c.String("input"))
if err != nil {
l.Println("Error parsing input file.")
Expand All @@ -94,15 +110,6 @@ func main() {
panic(err)
}
writer.Flush()

if c.Bool("warn") {
err = warn()
if err != nil {
l.Println("Error detecting warnings.")
os.Exit(1)
}
}

}

app.Run(os.Args)
Expand Down
10 changes: 5 additions & 5 deletions warn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import (
"os/exec"
)

func warn() error {
srcroot := os.Getenv("SRCROOT")
if srcroot == "" {
return fmt.Errorf("SRCROOT should not be nil")
func warn(directory string) error {
if directory == "" {
return fmt.Errorf("warn directory should not be nil")
}
find := exec.Command(
"/usr/bin/find",
srcroot,
directory,
"-name",
"*.swift",
"-print0",
Expand All @@ -29,6 +28,7 @@ func warn() error {
)
sed := exec.Command(
"sed",
"-E",
"s/(UIImage|NSImage).*/ warning: legacy use of imageNamed; consider using Resourceful/",
)

Expand Down

0 comments on commit 39b12e3

Please sign in to comment.