mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License-AGPL.txt in the project root for license information.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "gp",
|
|
Short: "Command line interface for Gitpod",
|
|
}
|
|
|
|
// Execute rusn the root command
|
|
func Execute() {
|
|
entrypoint := strings.TrimPrefix(filepath.Base(os.Args[0]), "gp-")
|
|
for _, c := range rootCmd.Commands() {
|
|
if c.Name() == entrypoint {
|
|
// we can't call subcommands directly (they just call their parents - thanks cobra),
|
|
// so instead we have to manipulate the os.Args
|
|
os.Args = append([]string{os.Args[0], entrypoint}, os.Args[1:]...)
|
|
break
|
|
}
|
|
}
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func getGitpodAPIToken() (string, error) {
|
|
apiToken := os.Getenv("GITPOD_REMOTE_APITOKEN")
|
|
if apiToken == "" {
|
|
return "", fmt.Errorf("No Gitpod API token present ($GITPOD_REMOTE_APITOKEN env var isn't set)")
|
|
}
|
|
|
|
return apiToken, nil
|
|
}
|
|
|
|
func getWorkspaceID() (string, error) {
|
|
result := os.Getenv("GITPOD_WORKSPACE_ID")
|
|
if result == "" {
|
|
return "", fmt.Errorf("No Gitpod workspace ID present ($GITPOD_WORKSPACE_ID env var isn't set)")
|
|
}
|
|
|
|
return result, nil
|
|
}
|