mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00
NOISSUE - Add insecure
param to cli (#356)
Signed-off-by: drasko <drasko.draskovic@gmail.com>
This commit is contained in:
parent
1683d17830
commit
af281da430
@ -30,8 +30,8 @@ var (
|
||||
)
|
||||
|
||||
// SetServerAddr - set addr using host and port
|
||||
func SetServerAddr(host string, port int) {
|
||||
serverAddr = fmt.Sprintf("https://%s", host)
|
||||
func SetServerAddr(proto string, host string, port int) {
|
||||
serverAddr = fmt.Sprintf("%s://%s", proto, host)
|
||||
|
||||
if port != 0 {
|
||||
serverAddr = fmt.Sprintf("%s:%s", serverAddr, strconv.Itoa(port))
|
||||
|
@ -10,19 +10,29 @@ import (
|
||||
func main() {
|
||||
|
||||
conf := struct {
|
||||
Host string
|
||||
Port int
|
||||
host string
|
||||
port int
|
||||
insecure bool
|
||||
}{
|
||||
"localhost",
|
||||
0,
|
||||
false,
|
||||
}
|
||||
|
||||
// Root
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "mainflux-cli",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Set HTTP server address
|
||||
cli.SetServerAddr(conf.Host, conf.Port)
|
||||
var proto string
|
||||
|
||||
if conf.insecure {
|
||||
proto = "http"
|
||||
} else {
|
||||
proto = "https"
|
||||
cli.SetCerts()
|
||||
}
|
||||
|
||||
cli.SetServerAddr(proto, conf.host, conf.port)
|
||||
},
|
||||
}
|
||||
|
||||
@ -42,9 +52,11 @@ func main() {
|
||||
|
||||
// Root Flags
|
||||
rootCmd.PersistentFlags().StringVarP(
|
||||
&conf.Host, "host", "m", conf.Host, "HTTP Host address")
|
||||
&conf.host, "host", "m", conf.host, "HTTP Host address")
|
||||
rootCmd.PersistentFlags().IntVarP(
|
||||
&conf.Port, "port", "p", conf.Port, "HTTP Host Port")
|
||||
&conf.port, "port", "p", conf.port, "HTTP Host Port")
|
||||
rootCmd.PersistentFlags().BoolVarP(
|
||||
&conf.insecure, "insecure", "i", false, "do not use TLS")
|
||||
|
||||
// Client and Channels Flags
|
||||
rootCmd.PersistentFlags().IntVarP(
|
||||
@ -52,9 +64,6 @@ func main() {
|
||||
rootCmd.PersistentFlags().IntVarP(
|
||||
&cli.Offset, "offset", "o", 0, "offset query parameter")
|
||||
|
||||
// Set TLS certificates
|
||||
cli.SetCerts()
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user