fix: enable and disable remote links
This commit is contained in:
parent
ac0aa0de5a
commit
42aa07802a
24
cmd/remote/disable.go
Normal file
24
cmd/remote/disable.go
Normal file
@ -0,0 +1,24 @@
|
||||
package remote
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/remote"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var disableRemoteCmd = &cobra.Command{
|
||||
Use: "disable",
|
||||
Short: "Disable Remove Server",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := remote.Disable(args[0], configDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
remoteCmd.AddCommand(disableRemoteCmd)
|
||||
}
|
24
cmd/remote/enable.go
Normal file
24
cmd/remote/enable.go
Normal file
@ -0,0 +1,24 @@
|
||||
package remote
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/remote"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var enableRemoteCmd = &cobra.Command{
|
||||
Use: "enable",
|
||||
Short: "Enable Remove Server",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := remote.Enable(args[0], configDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
remoteCmd.AddCommand(enableRemoteCmd)
|
||||
}
|
@ -32,6 +32,62 @@ func Add(remote *types.Remote, configDir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enable a remote link
|
||||
func Enable(remoteName string, configDir string) error {
|
||||
|
||||
cnf, err := config.Read(configDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// search after duplicate remote_names
|
||||
var found bool
|
||||
for _, r := range cnf.Remotes {
|
||||
if r.Name == remoteName {
|
||||
r.Enabled = true
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return fmt.Errorf("Can not find remote %v", remoteName)
|
||||
}
|
||||
|
||||
if err := config.Write(cnf, configDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable a remote link
|
||||
func Disable(remoteName string, configDir string) error {
|
||||
|
||||
cnf, err := config.Read(configDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// search after duplicate remote_names
|
||||
var found bool
|
||||
for _, r := range cnf.Remotes {
|
||||
if r.Name == remoteName {
|
||||
r.Enabled = false
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return fmt.Errorf("Can not find remote %v", remoteName)
|
||||
}
|
||||
|
||||
if err := config.Write(cnf, configDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func List(w io.Writer, configDir string) error {
|
||||
|
||||
configuration, err := config.Read(configDir)
|
||||
@ -41,10 +97,10 @@ func List(w io.Writer, configDir string) error {
|
||||
|
||||
tw := tabwriter.NewWriter(w, 0, 0, 5, ' ', 0)
|
||||
|
||||
fmt.Fprint(tw, "name\taddress\tregistered\n")
|
||||
fmt.Fprint(tw, "name\taddress\tenabled\tregistered\n")
|
||||
|
||||
for _, remote := range configuration.Remotes {
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\n", remote.Name, remote.Address, remote.Registered)
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\n", remote.Name, remote.Address, remote.Enabled, remote.Registered)
|
||||
}
|
||||
|
||||
tw.Flush()
|
||||
|
Loading…
Reference in New Issue
Block a user