made cli into sub files for modularity
This commit is contained in:
19
cmd/action.go
Normal file
19
cmd/action.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.sr.ht/~akilan1999/p2p-rendering-computation/server"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CliAction = func(ctx *cli.Context) error {
|
||||||
|
if Mode == "server" {
|
||||||
|
server.Server()
|
||||||
|
}
|
||||||
|
|
||||||
|
//Call function to create Docker container
|
||||||
|
if IpAddress != "" {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
31
cmd/flags.go
Normal file
31
cmd/flags.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Mode,IpAddress string
|
||||||
|
var List_servers, Ip_table bool
|
||||||
|
|
||||||
|
var AppConfigFlags = []cli.Flag{
|
||||||
|
// Deprecated to be implemented using GRPC
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "Mode",
|
||||||
|
Value: "server",
|
||||||
|
Usage: "Specifies mode of running",
|
||||||
|
EnvVars: []string{"P2P_MODE"},
|
||||||
|
Destination: &Mode,
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "ListServers",
|
||||||
|
Usage: "List servers which can render tasks",
|
||||||
|
EnvVars: []string{"LIST_SERVERS"},
|
||||||
|
Destination: &List_servers,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "CreateVM",
|
||||||
|
Usage: "Creates Docker container on the selected server",
|
||||||
|
EnvVars: []string{"CREATE_VM"},
|
||||||
|
Destination: &IpAddress,
|
||||||
|
},
|
||||||
|
}
|
||||||
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ require (
|
|||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||||
github.com/docker/distribution v2.7.1+incompatible // indirect
|
github.com/docker/distribution v2.7.1+incompatible // indirect
|
||||||
github.com/docker/docker v20.10.0-beta1.0.20201113105859-b6bfff2a628f+incompatible
|
github.com/docker/docker v20.10.0-beta1.0.20201113105859-b6bfff2a628f+incompatible
|
||||||
github.com/docker/go-connections v0.4.0 // indirect
|
github.com/docker/go-connections v0.4.0
|
||||||
github.com/docker/go-units v0.4.0 // indirect
|
github.com/docker/go-units v0.4.0 // indirect
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||||
|
|||||||
1
go.sum
1
go.sum
@@ -566,6 +566,7 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
|
|||||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
|
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
|
||||||
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
|
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
|
||||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||||
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
|
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
|
||||||
|
|||||||
105
main.go
105
main.go
@@ -1,15 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/p2p"
|
"git.sr.ht/~akilan1999/p2p-rendering-computation/cmd"
|
||||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/server"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VERSION specifies the version of the platform
|
// VERSION specifies the version of the platform
|
||||||
var VERSION = "0.0.1"
|
var VERSION = "1.0.0"
|
||||||
var mode string
|
var mode string
|
||||||
|
|
||||||
// Varaibles if mode is client
|
// Varaibles if mode is client
|
||||||
@@ -18,53 +17,59 @@ var List_servers, Ip_table bool
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
app := &cli.App{
|
app := cli.NewApp()
|
||||||
Name: "p2p-rendering-computation",
|
app.Name = "p2p-rendering-computation"
|
||||||
Usage: "allows you to batch tasks in a peer to peer network",
|
app.Usage = "p2p cli application to create and access VMs in other servers"
|
||||||
Version: VERSION,
|
app.Version = VERSION
|
||||||
Flags: []cli.Flag {
|
app.Flags = cmd.AppConfigFlags
|
||||||
&cli.StringFlag{
|
app.Action = cmd.CliAction
|
||||||
Name: "mode",
|
//app := &cli.App{
|
||||||
Value: "client",
|
// Name: "p2p-rendering-computation",
|
||||||
Usage: "Specifies mode of running",
|
// Usage: "allows you to batch tasks in a peer to peer network",
|
||||||
Destination: &mode,
|
// Version: VERSION,
|
||||||
},
|
// Flags: []cli.Flag {
|
||||||
/* list servers */
|
// &cli.StringFlag{
|
||||||
&cli.BoolFlag{
|
// Name: "mode",
|
||||||
Name: "List-servers",
|
// Value: "client",
|
||||||
Usage: "List servers which can render tasks",
|
// Usage: "Specifies mode of running",
|
||||||
Destination: &List_servers,
|
// Destination: &mode,
|
||||||
},
|
// },
|
||||||
/* List iptable */
|
// /* list servers */
|
||||||
&cli.BoolFlag{
|
// &cli.BoolFlag{
|
||||||
Name: "Ip-table",
|
// Name: "List-servers",
|
||||||
Usage: "Listing servers that can be connected to",
|
// Usage: "List servers which can render tasks",
|
||||||
Destination: &Ip_table,
|
// Destination: &List_servers,
|
||||||
},
|
// },
|
||||||
|
// /* List iptable */
|
||||||
},
|
// &cli.BoolFlag{
|
||||||
/*action for all flags*/
|
// Name: "Ip-table",
|
||||||
Action: func(c *cli.Context) error {
|
// Usage: "Listing servers that can be connected to",
|
||||||
/* action when certain flags are selected */
|
// Destination: &Ip_table,
|
||||||
/*if Run_script == "None" {
|
// },
|
||||||
fmt.Println("script not excuted as run script not selected")
|
//
|
||||||
}*/
|
// },
|
||||||
|
// /*action for all flags*/
|
||||||
if Ip_table == true || List_servers == true{
|
// Action: func(c *cli.Context) error {
|
||||||
err := p2p.PrintIpTable()
|
// /* action when certain flags are selected */
|
||||||
if err != nil {
|
// /*if Run_script == "None" {
|
||||||
log.Fatal(err)
|
// fmt.Println("script not excuted as run script not selected")
|
||||||
}
|
// }*/
|
||||||
}
|
//
|
||||||
|
// if Ip_table == true || List_servers == true{
|
||||||
// If mode server is selected
|
// err := p2p.PrintIpTable()
|
||||||
if mode == "server"{
|
// if err != nil {
|
||||||
server.Server()
|
// log.Fatal(err)
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
return nil
|
//
|
||||||
},
|
// // If mode server is selected
|
||||||
}
|
// if mode == "server"{
|
||||||
|
// server.Server()
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return nil
|
||||||
|
// },
|
||||||
|
//}
|
||||||
|
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user