1// Copyright 2018 The CUE Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cmd
16
17import (
18	"fmt"
19	"os"
20
21	"github.com/spf13/cobra"
22)
23
24func newGetCmd(c *Command) *cobra.Command {
25	cmd := &cobra.Command{
26		Use:   "get <language> [packages]",
27		Short: "add dependencies to the current module",
28		Long: `Get downloads packages or modules for CUE or another language
29to include them in the module's pkg directory.
30
31Get requires an additional language field to determine for which
32language definitions should be fetched. If get fetches definitions
33for a language other than CUE, the definitions are extracted from
34the source of the respective language and stored.
35The specifics on how dependencies are fechted and converted vary
36per language and are documented in the respective subcommands.
37`,
38		RunE: mkRunE(c, func(cmd *Command, args []string) error {
39			stderr := cmd.Stderr()
40			if len(args) == 0 {
41				fmt.Fprintln(stderr, "get must be run as one of its subcommands")
42			} else {
43				fmt.Fprintf(stderr, "get must be run as one of its subcommands: unknown subcommand %q\n", args[0])
44			}
45			fmt.Fprintln(stderr, "Run 'cue help get' for known subcommands.")
46			os.Exit(1) // TODO: get rid of this
47			return nil
48		}),
49	}
50	cmd.AddCommand(newGoCmd(c))
51	return cmd
52}
53