2023-06-05 23:16:23 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/databricks/cli/cmd/root"
|
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
func newCatCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "cat FILE_PATH",
|
|
|
|
Short: "Show file content",
|
|
|
|
Long: `Show the contents of a file.`,
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
PreRunE: root.MustWorkspaceClient,
|
|
|
|
}
|
2023-06-05 23:16:23 +00:00
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
2023-06-05 23:16:23 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
|
2023-06-16 15:09:08 +00:00
|
|
|
f, path, err := filerForPath(ctx, args[0])
|
2023-06-05 23:16:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := f.Read(ctx, path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return cmdio.RenderReader(ctx, r)
|
2023-07-27 10:03:08 +00:00
|
|
|
}
|
2023-06-05 23:16:23 +00:00
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
return cmd
|
2023-06-05 23:16:23 +00:00
|
|
|
}
|