File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package controllers
2+
3+ import (
4+ "errors"
5+ "fmt"
6+ "gopkg.in/urfave/cli.v2"
7+ )
8+
9+ var InitCommand = cli.Command {
10+ Name : "init" ,
11+ Aliases : []string {"i" },
12+ Usage : "init <path>" ,
13+ UsageText : "Will create the minimal folder structure which is required by packman" ,
14+ Action : func (context * cli.Context ) error {
15+
16+ if context .NArg () != 1 {
17+ fmt .Println ("init expects exactly 1 argument" )
18+ }
19+
20+ path := context .Args ().Get (0 )
21+
22+ if path == "" {
23+ return errors .New ("you must provide a path to the project" )
24+ }
25+
26+ return PackmanModule .ProjectInit .Init (path )
27+ },
28+ }
Original file line number Diff line number Diff line change 11package controllers
2+
3+ import "gopkg.in/urfave/cli.v2"
4+
5+ var PackCommand = cli.Command {
6+ Name : "pack" ,
7+ Aliases : []string {"p" },
8+ Usage : "pack <package-name> <path>" ,
9+ UsageText : "Will pack the given folder and push it to the backend so it can be later located using the package-name" ,
10+ Action : func (context * cli.Context ) error {
11+ return nil
12+ },
13+ }
Original file line number Diff line number Diff line change 11package controllers
2+
3+ import (
4+ "github.com/securenative/packman/cmd/packman/lib"
5+ )
6+
7+ var PackmanModule * lib.PackmanModule
Original file line number Diff line number Diff line change 11package controllers
2+
3+ import "gopkg.in/urfave/cli.v2"
4+
5+ var UnpackCommand = cli.Command {
6+ Name : "unpack" ,
7+ Aliases : []string {"u" },
8+ Usage : "unpack <package-name> <dest-path>" ,
9+ UsageText : "Will unpack the given package to the given destination path" ,
10+ Action : func (context * cli.Context ) error {
11+ return nil
12+ },
13+ }
Original file line number Diff line number Diff line change 11package lib
2+
3+ type PackmanConfig struct {
4+ ConfigPath string
5+ }
Original file line number Diff line number Diff line change 11package lib
2+
3+ import (
4+ "github.com/securenative/packman/internal/business"
5+ "github.com/securenative/packman/internal/data"
6+ "gopkg.in/urfave/cli.v2"
7+ )
8+
9+ type PackmanModule struct {
10+ Config PackmanConfig
11+ configStore data.ConfigStore
12+ backend data.Backend
13+ templateEngine data.TemplateEngine
14+ scriptEngine data.ScriptEngine
15+
16+ ProjectInit business.ProjectInit
17+ Packer business.Packer
18+ Unpacker business.Unpacker
19+
20+ Commands []* cli.Command
21+ }
22+
23+ func NewPackmanModule (config PackmanConfig , commands []* cli.Command ) * PackmanModule {
24+
25+ configStore := data .NewLocalConfigStore (config .ConfigPath )
26+ backend := data .NewGithubBackend (configStore )
27+ template := data .NewGoTemplateEngine ()
28+ script := data .NewGoScriptEngine ()
29+
30+ init := business .NewGitProjectInit ()
31+ packer := business .NewPackmanPacker (backend )
32+ unpacker := business .NewPackmanUnpacker (backend , template , script )
33+
34+ return & PackmanModule {
35+ Config : config ,
36+ configStore : configStore ,
37+ backend : backend ,
38+ templateEngine : template ,
39+ scriptEngine : script ,
40+ ProjectInit : init ,
41+ Packer : packer ,
42+ Unpacker : unpacker ,
43+ Commands : commands ,
44+ }
45+ }
Original file line number Diff line number Diff line change 1- package packman
1+ package main
2+
3+ import (
4+ "github.com/securenative/packman/cmd/packman/controllers"
5+ "github.com/securenative/packman/cmd/packman/lib"
6+ "gopkg.in/urfave/cli.v2"
7+ "os"
8+ "path/filepath"
9+ )
10+
11+ func main () {
12+
13+ cfg := parseConfig ()
14+ module := lib .NewPackmanModule (cfg , []* cli.Command {
15+ & controllers .InitCommand ,
16+ & controllers .PackCommand ,
17+ & controllers .UnpackCommand ,
18+ })
19+ controllers .PackmanModule = module
20+
21+ app := cli.App {
22+ Name : "packman" ,
23+ Version : "0.1" ,
24+ Commands : module .Commands ,
25+ }
26+
27+ err := app .Run (os .Args )
28+ if err != nil {
29+ panic (err .Error ())
30+ }
31+ }
32+
33+ func parseConfig () lib.PackmanConfig {
34+ home , err := os .UserHomeDir ()
35+ if err != nil {
36+ panic (err .Error ())
37+ }
38+ configPath := filepath .Join (home , ".packman" )
39+ cfg := lib.PackmanConfig {
40+ ConfigPath : configPath ,
41+ }
42+ return cfg
43+ }
Original file line number Diff line number Diff line change @@ -6,4 +6,5 @@ require (
66 github.com/google/go-github/v25 v25.0.2
77 github.com/stretchr/testify v1.3.0
88 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
9+ gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8
910)
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ type PackmanPacker struct {
66 backend data.Backend
77}
88
9+ func NewPackmanPacker (backend data.Backend ) * PackmanPacker {
10+ return & PackmanPacker {backend : backend }
11+ }
12+
913func (this * PackmanPacker ) Pack (name string , sourcePath string ) error {
1014 return this .backend .Push (name , sourcePath )
1115}
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments