Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
f554844f
Commit
f554844f
authored
7 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
Added command line interface
parent
0512114a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/root.go
+93
-0
93 additions, 0 deletions
cmd/root.go
glide.yaml
+4
-0
4 additions, 0 deletions
glide.yaml
globals/message.go
+4
-1
4 additions, 1 deletion
globals/message.go
main.go
+12
-0
12 additions, 0 deletions
main.go
with
113 additions
and
1 deletion
cmd/root.go
0 → 100644
+
93
−
0
View file @
f554844f
// Copyright © 2018 Privategrity Corporation
//
// All rights reserved.
// Package cmd initializes the CLI and config parsers as well as the logger.
package
cmd
import
(
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/privategrity/client/api"
)
var
verbose
bool
var
userId
int
var
serverAddr
string
var
message
string
// Execute adds all child commands to the root command and sets flags
// appropriately. This is called by main.main(). It only needs to
// happen once to the rootCmd.
func
Execute
()
{
if
err
:=
rootCmd
.
Execute
();
err
!=
nil
{
jww
.
ERROR
.
Println
(
err
)
os
.
Exit
(
1
)
}
}
// rootCmd represents the base command when called without any subcommands
var
rootCmd
=
&
cobra
.
Command
{
Use
:
"client"
,
Short
:
"Runs a client for cMix anonymous communication platform"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
api
.
Login
(
userId
,
serverAddr
)
api
.
Send
(
userId
,
message
)
for
{
msg
:=
api
.
TryReceive
()
if
msg
!=
""
{
jww
.
INFO
.
Printf
(
"Message Received: %s"
,
msg
)
break
}
}
},
}
// init is the initialization function for Cobra which defines commands
// and flags.
func
init
()
{
cobra
.
OnInitialize
(
initConfig
,
initLog
)
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd
.
PersistentFlags
()
.
BoolVarP
(
&
verbose
,
"verbose"
,
"v"
,
false
,
"Verbose mode for debugging"
)
rootCmd
.
PersistentFlags
()
.
IntVarP
(
&
userId
,
"userid"
,
"i"
,
0
,
"UserID to sign in as"
)
rootCmd
.
MarkPersistentFlagRequired
(
"userid"
)
rootCmd
.
PersistentFlags
()
.
StringVarP
(
&
serverAddr
,
"serveraddr"
,
"s"
,
""
,
"Server address to send messages to"
)
rootCmd
.
MarkPersistentFlagRequired
(
"serveraddr"
)
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd
.
Flags
()
.
BoolP
(
"toggle"
,
"t"
,
false
,
"Help message for toggle"
)
rootCmd
.
Flags
()
.
StringVarP
(
&
message
,
"message"
,
"m"
,
""
,
"Message to send"
)
}
// initConfig reads in config file and ENV variables if set.
func
initConfig
()
{}
// initLog initializes logging thresholds and the log path.
func
initLog
()
{
// If verbose flag set then log more info for debugging
if
verbose
||
viper
.
GetBool
(
"verbose"
)
{
jww
.
SetLogThreshold
(
jww
.
LevelDebug
)
jww
.
SetStdoutThreshold
(
jww
.
LevelDebug
)
}
else
{
jww
.
SetLogThreshold
(
jww
.
LevelInfo
)
jww
.
SetStdoutThreshold
(
jww
.
LevelInfo
)
}
// Create log file, overwrites if existing
logPath
:=
viper
.
GetString
(
"logPath"
)
logFile
,
err
:=
os
.
Create
(
logPath
)
if
err
!=
nil
{
jww
.
WARN
.
Println
(
"Invalid or missing log path, default path used."
)
}
else
{
jww
.
SetLogOutput
(
logFile
)
}
}
This diff is collapsed.
Click to expand it.
glide.yaml
+
4
−
0
View file @
f554844f
...
...
@@ -8,3 +8,7 @@ import:
version
:
ClientComms
repo
:
git@gitlab.com:privategrity/comms
vcs
:
git
-
package
:
github.com/spf13/cobra
version
:
^0.0.1
subpackages
:
-
cobra
This diff is collapsed.
Click to expand it.
globals/message.go
+
4
−
1
View file @
f554844f
...
...
@@ -2,6 +2,7 @@ package globals
import
(
"encoding/binary"
jww
"github.com/spf13/jwalterweatherman"
)
// Defines message structure. Based the "Basic Message Structure" doc
...
...
@@ -56,7 +57,9 @@ func NewMessage(sid uint64, messageString string) *Message {
func
ConstructMessageFromBytes
(
msg
*
[]
byte
)
*
Message
{
if
uint32
(
len
(
*
msg
))
!=
TOTAL_LEN
||
(
*
msg
)[
0
]
!=
0
{
panic
(
"invalid message bytes passed"
)
jww
.
ERROR
.
Printf
(
"Invalid message bytes passed! Got %v expected %v"
,
len
(
*
msg
),
TOTAL_LEN
)
panic
(
"Invalid message bytes passed"
)
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
main.go
0 → 100644
+
12
−
0
View file @
f554844f
// Copyright © 2018 Privategrity Corporation
//
// All rights reserved.
package
main
import
"gitlab.com/privategrity/client/cmd"
// main needs no introduction.
func
main
()
{
cmd
.
Execute
()
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment