Path: blob/main/components/ws-daemon/cmd/client-init.go
2498 views
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"context"89"github.com/alecthomas/repr"10"github.com/spf13/cobra"1112"github.com/gitpod-io/gitpod/common-go/log"13csapi "github.com/gitpod-io/gitpod/content-service/api"14"github.com/gitpod-io/gitpod/ws-daemon/api"15)1617// clientInitCmd starts a new workspace18var clientInitCmd = &cobra.Command{19Use: "init <request.json>",20Short: "initialize a workspace",21Args: cobra.ExactArgs(0),22Run: func(cmd *cobra.Command, args []string) {23// fc, err := os.ReadFile(args[0])24// if err != nil {25// log.WithError(err).Fatal("cannot read init request")26// }2728// var initReq api.InitWorkspaceRequest29// if err := json.Unmarshal(fc, &initReq); err != nil {30// log.WithError(err).Fatal("cannot parse init request")31// }3233initReq := api.InitWorkspaceRequest{34Id: "foobar",35Metadata: &api.WorkspaceMetadata{36Owner: "chris",37MetaId: "foofoo",38},39Initializer: &csapi.WorkspaceInitializer{40Spec: &csapi.WorkspaceInitializer_Git{41Git: &csapi.GitInitializer{42RemoteUri: "https://github.com/32leaves/bel",43TargetMode: csapi.CloneTargetMode_REMOTE_HEAD,44CheckoutLocation: "bel",45Config: &csapi.GitConfig{46Authentication: csapi.GitAuthMethod_NO_AUTH,47},48},49},50},51}5253conn, err := getGRPCConnection()54if err != nil {55log.WithError(err).Fatal("cannot connect")56}57defer conn.Close()5859client := api.NewWorkspaceContentServiceClient(conn)60resp, err := client.InitWorkspace(context.Background(), &initReq)61if err != nil {62log.WithError(err).Fatal("error during RPC call")63}6465repr.Println(resp)66},67}6869func init() {70clientCmd.AddCommand(clientInitCmd)71// clientInitCmd.Flags().BoolVar(&startWorkspaceReq.Headless, "headless", false, "start a headless workspace")72// clientInitCmd.Flags().StringVarP(&startWorkspaceReq.ServicePrefix, "service-prefix", "p", "", "use a service prefix different from the workspace ID")73// clientInitCmd.Flags().StringVar(&startWorkspaceReq.Metadata.Owner, "owner", "foobar", "set the workspace owner")74}757677