github.com/joshdk/godel@v0.0.0-20170529232908-862138a45aee/apps/okgo/app.go (about) 1 // Copyright 2016 Palantir Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package okgo 16 17 import ( 18 "go/build" 19 20 "github.com/nmiyake/pkg/dirs" 21 "github.com/nmiyake/pkg/errorstringer" 22 "github.com/palantir/amalgomate/amalgomated" 23 "github.com/palantir/pkg/cli" 24 "github.com/palantir/pkg/cli/cfgcli" 25 26 "github.com/palantir/godel/apps/okgo/cmd" 27 "github.com/palantir/godel/apps/okgo/cmd/cmdlib" 28 "github.com/palantir/godel/apps/okgo/config" 29 ) 30 31 func RunApp(args []string, supplier amalgomated.CmderSupplier) int { 32 return amalgomated.RunApp(args, nil, cmdlib.Instance(), App(supplier).Run) 33 } 34 35 func App(supplier amalgomated.CmderSupplier) *cli.App { 36 if releaseTag := cmd.GetReleaseTagEnvVar(); releaseTag != "" { 37 // if ReleaseTag is specified and is found in the default build config, update default build config to 38 // only include tags that occur before the provided release tag. 39 var newRelTags []string 40 for _, currTag := range build.Default.ReleaseTags { 41 newRelTags = append(newRelTags, currTag) 42 if releaseTag == currTag { 43 // if this tag matches, do not include any of the newer tags 44 break 45 } 46 } 47 build.Default.ReleaseTags = newRelTags 48 } 49 50 app := cli.NewApp(cfgcli.Handler(), cli.DebugHandler(errorstringer.StackWithInterleavedMessages)) 51 app.Name = "okgo" 52 app.Usage = "Run static checks for project" 53 54 // add runAll and individual checks 55 runAllCmd := cmd.RunAllCommand(supplier) 56 app.Subcommands = []cli.Command{ 57 runAllCmd, 58 } 59 for _, currCmd := range cmdlib.Instance().Cmds() { 60 app.Subcommands = append(app.Subcommands, cmd.SingleCheckCommand(currCmd, supplier)) 61 } 62 // set default action to runAll 63 app.Action = func(ctx cli.Context) error { 64 cfg, err := config.Load(cfgcli.ConfigPath, cfgcli.ConfigJSON) 65 if err != nil { 66 return err 67 } 68 wd, err := dirs.GetwdEvalSymLinks() 69 if err != nil { 70 return err 71 } 72 if err := cmd.SetReleaseTagEnvVar(cfg.ReleaseTag); err != nil { 73 return err 74 } 75 return cmd.DoRunAll(nil, cfg, supplier, wd, ctx.App.Stdout) 76 } 77 return app 78 }