Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use tedsuo/rata and jessevdk/go-flags
[#117750485] Signed-off-by: Chris Hendrix <chendrix@pivotal.io>
- Loading branch information
Showing
54 changed files
with
5,613 additions
and
786 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,79 @@ | ||
package main | ||
|
||
import "github.com/cloudfoundry-incubator/cli-plugin-repo/app" | ||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"net/http" | ||
|
||
"github.com/cloudfoundry-incubator/cli-plugin-repo/models" | ||
"github.com/cloudfoundry-incubator/cli-plugin-repo/parser" | ||
"github.com/cloudfoundry-incubator/cli-plugin-repo/server" | ||
"github.com/jessevdk/go-flags" | ||
"github.com/tedsuo/rata" | ||
) | ||
|
||
type CLIPR struct { | ||
Port int `short:"p" long:"port" default:"8080" description:"Port that the plugin repo listens on"` | ||
RepoIndexPath string `short:"f" long:"filepath" default:"repo-index.yml" description:"Path to repo-index file"` | ||
} | ||
|
||
func main() { | ||
app.Start() | ||
cmd := &CLIPR{} | ||
|
||
parser := flags.NewParser(cmd, flags.Default) | ||
parser.NamespaceDelimiter = "-" | ||
|
||
args, err := parser.Parse() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
err = cmd.Execute(args) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func (cmd *CLIPR) Execute(args []string) error { | ||
logger := os.Stdout //turn this into a logger soon | ||
|
||
model := models.NewPlugins(logger) | ||
|
||
yamlParser := parser.NewYamlParser("repo-index.yml", logger, model) | ||
handles := server.NewServerHandles(yamlParser, logger) | ||
|
||
handlers := map[string]http.Handler{ | ||
Index: http.FileServer(http.Dir("ui")), | ||
List: http.HandlerFunc(handles.ListPlugins), | ||
} | ||
|
||
router, err := rata.NewRouter(Routes, handlers) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
err = http.ListenAndServe(cmd.bindAddr(), router) | ||
|
||
return err | ||
} | ||
|
||
func (cmd *CLIPR) bindAddr() string { | ||
return fmt.Sprintf(":%d", cmd.Port) | ||
} | ||
|
||
const ( | ||
Index = "Index" | ||
List = "List" | ||
) | ||
|
||
var Routes = rata.Routes([]rata.Route{ | ||
{Path: "/", Method: "GET", Name: Index}, | ||
{Path: "/js/:file", Method: "GET", Name: Index}, | ||
{Path: "/css/:file", Method: "GET", Name: Index}, | ||
{Path: "/font/:file", Method: "GET", Name: Index}, | ||
{Path: "/images/:file", Method: "GET", Name: Index}, | ||
{Path: "/list", Method: "GET", Name: List}, | ||
}) |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.