talm

Форк
0
/
imported_read.go 
85 строк · 2.1 Кб
1
// Code generated by go run tools/import_commands.go --talos-version v1.7.1 read
2
// DO NOT EDIT.
3

4
// This Source Code Form is subject to the terms of the Mozilla Public
5
// License, v. 2.0. If a copy of the MPL was not distributed with this
6
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7

8
package commands
9

10
import (
11
	"context"
12
	"fmt"
13
	"io"
14
	"os"
15

16
	"github.com/spf13/cobra"
17

18
	"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
19
	"github.com/siderolabs/talos/pkg/machinery/client"
20
)
21

22
// readCmd represents the read command.
23
var readCmd = &cobra.Command{
24
	Use:     "read <path>",
25
	Short:   "Read a file on the machine",
26
	Long:    ``,
27
	Args:    cobra.ExactArgs(1),
28
	Aliases: []string{"cat"},
29
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
30
		if len(args) != 0 {
31
			return nil, cobra.ShellCompDirectiveError | cobra.ShellCompDirectiveNoFileComp
32
		}
33

34
		return completePathFromNode(toComplete), cobra.ShellCompDirectiveNoFileComp
35
	},
36
	RunE: func(cmd *cobra.Command, args []string) error {
37
		return WithClient(func(ctx context.Context, c *client.Client) error {
38
			if err := helpers.FailIfMultiNodes(ctx, "read"); err != nil {
39
				return err
40
			}
41

42
			r, err := c.Read(ctx, args[0])
43
			if err != nil {
44
				return fmt.Errorf("error reading file: %w", err)
45
			}
46

47
			defer r.Close() //nolint:errcheck
48

49
			_, err = io.Copy(os.Stdout, r)
50
			if err != nil {
51
				return fmt.Errorf("error reading: %w", err)
52
			}
53

54
			return r.Close()
55
		})
56
	},
57
}
58

59
func init() {
60
	readCmd.Flags().StringSliceVarP(&readCmdFlags.configFiles, "file",
61
		"f", nil, "specify config files or patches in a YAML file (can specify multiple)",
62
	)
63
	readCmd.PreRunE = func(cmd *cobra.Command,
64

65
		args []string) error {
66
		nodesFromArgs :=
67
			len(GlobalArgs.
68
				Nodes) > 0
69
		endpointsFromArgs := len(GlobalArgs.Endpoints) > 0
70
		for _, configFile := range readCmdFlags.configFiles {
71
			if err := processModelineAndUpdateGlobals(configFile, nodesFromArgs,
72
				endpointsFromArgs, false,
73
			); err != nil {
74
				return err
75
			}
76
		}
77
		return nil
78
	}
79

80
	addCommand(readCmd)
81
}
82

83
var readCmdFlags struct {
84
	configFiles []string
85
}
86

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.