add group preview subcommand
This commit is contained in:
parent
7ff5492156
commit
ec276e5411
2 changed files with 80 additions and 0 deletions
78
cmd/signaldctl/cmd/group/preview/preview.go
Normal file
78
cmd/signaldctl/cmd/group/preview/preview.go
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
// Copyright © 2021 Finn Herzfeld <finn@janky.solutions>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package preview
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||||
|
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
account string
|
||||||
|
joinURL string
|
||||||
|
PreviewGroupCmd = &cobra.Command{
|
||||||
|
Use: "preview https://signal.group/...",
|
||||||
|
Short: "preview information about a group without joining",
|
||||||
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if account == "" {
|
||||||
|
account = config.Config.DefaultAccount
|
||||||
|
}
|
||||||
|
if account == "" {
|
||||||
|
common.Must(cmd.Help())
|
||||||
|
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) == 0 {
|
||||||
|
return errors.New("please specify signald.group URL")
|
||||||
|
}
|
||||||
|
joinURL = args[0]
|
||||||
|
|
||||||
|
if !strings.HasPrefix(joinURL, "https://signal.group/#") {
|
||||||
|
return errors.New("invalid group link (must start with https://signal.group/#")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
RunE: func(_ *cobra.Command, args []string) error {
|
||||||
|
go common.Signald.Listen(nil)
|
||||||
|
req := v1.GroupLinkInfoRequest{
|
||||||
|
Account: account,
|
||||||
|
Uri: joinURL,
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := req.Submit(common.Signald)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch common.OutputFormat {
|
||||||
|
case common.OutputFormatJSON, common.OutputFormatDefault:
|
||||||
|
return json.NewEncoder(os.Stdout).Encode(info)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/join"
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/join"
|
||||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/leave"
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/leave"
|
||||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/list"
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/list"
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/preview"
|
||||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/removemember"
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/removemember"
|
||||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/show"
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/show"
|
||||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/update"
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/update"
|
||||||
|
@ -41,6 +42,7 @@ func init() {
|
||||||
GroupCmd.AddCommand(join.JoinGroupCmd)
|
GroupCmd.AddCommand(join.JoinGroupCmd)
|
||||||
GroupCmd.AddCommand(leave.LeaveGroupCmd)
|
GroupCmd.AddCommand(leave.LeaveGroupCmd)
|
||||||
GroupCmd.AddCommand(list.ListGroupCmd)
|
GroupCmd.AddCommand(list.ListGroupCmd)
|
||||||
|
GroupCmd.AddCommand(preview.PreviewGroupCmd)
|
||||||
GroupCmd.AddCommand(removemember.RemoveMemberCmd)
|
GroupCmd.AddCommand(removemember.RemoveMemberCmd)
|
||||||
GroupCmd.AddCommand(show.ShowGroupCmd)
|
GroupCmd.AddCommand(show.ShowGroupCmd)
|
||||||
GroupCmd.AddCommand(update.UpdateGroupCmd)
|
GroupCmd.AddCommand(update.UpdateGroupCmd)
|
||||||
|
|
Loading…
Reference in a new issue