-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from bsach64/cli-options
Cli options
- Loading branch information
Showing
6 changed files
with
66 additions
and
28 deletions.
There are no files selected for viewing
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,2 +1,3 @@ | ||
private/* | ||
tmp/* | ||
goback |
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 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/bsach64/goback/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
clientCmd = &cobra.Command{ | ||
Use: "client -u [user] -p [password] -H [host_addr] -f [filepath]", | ||
Short: "starts a client that connects to [host_addr] and sends [filepath]", | ||
Long: "starts a client that connects to [host_addr] and sends [filepath]", | ||
Run: StartClient, | ||
} | ||
|
||
clientArgs struct { | ||
user string | ||
password string | ||
host string | ||
f string | ||
} | ||
) | ||
|
||
func StartClient(cmd *cobra.Command, args []string) { | ||
c, err := client.ConnectToServer(clientArgs.user, clientArgs.password, clientArgs.host) | ||
if err != nil { | ||
log.Fatalf("Failed to connect to server: %v", err) | ||
} | ||
defer c.Close() | ||
client.Upload(c, clientArgs.f) | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(clientCmd) | ||
clientCmd.Flags().StringVarP(&clientArgs.user, "user", "u", "demo", "username") | ||
clientCmd.Flags().StringVarP(&clientArgs.password, "password", "p", "password", "password") | ||
clientCmd.Flags().StringVarP(&clientArgs.host, "host", "H", "127.0.0.1:2022", "host address") | ||
clientCmd.Flags().StringVarP(&clientArgs.f, "filepath", "f", "", "file path") | ||
clientCmd.MarkFlagRequired("filepath") | ||
} |
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 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/bsach64/goback/server" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var serverCmd = &cobra.Command{ | ||
Use: "server", | ||
Short: "starts a server", | ||
Long: "starts a server", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
server.Listen() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(serverCmd) | ||
} |
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,21 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
// "fmt" | ||
"time" | ||
|
||
"github.com/bsach64/goback/client" | ||
"github.com/bsach64/goback/server" | ||
// "github.com/bsach64/goback/utils" | ||
"github.com/bsach64/goback/cmd" | ||
) | ||
|
||
func main() { | ||
// f, err := utils.ChunkFile("example.txt") | ||
|
||
go server.Listen() | ||
time.Sleep(2 * time.Second) | ||
client.Upload("example.txt") | ||
|
||
cmd.Execute() | ||
} | ||
|
||
// Push this where |