content

package
v0.21.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "Adds a new content or updates an existing.",
	Long: `Adds a new content or updates an existing. For example:
mim content add file=myfile.json

or

cat myfile.json | mim content add

`,
	Run: func(cmd *cobra.Command, args []string) {
		server, token, err := login.ResolveCredentials()
		utils.HandleError(err)

		id, err := cmd.Flags().GetString("id")
		utils.HandleError(err)
		file, err := cmd.Flags().GetString("file")

		pterm.EnableDebugMessages()

		pterm.DefaultSection.Println("Adding content to " + server + "/content/" + id)

		conf, err := utils.ReadInput(file)
		utils.HandleError(err)

		content, err := convert(conf)
		utils.HandleError(err)

		conf, err = updateId(id, content)
		utils.HandleError(err)

		pterm.Success.Println("Read content file")

		_, err = web.PostRequest(server, token, "/content", conf)
		utils.HandleError(err)

		pterm.Success.Println("Added content to server")
		pterm.Println()
	},
	TraverseChildren: true,
}
View Source
var DeleteCmd = &cobra.Command{
	Use:   "delete",
	Short: "Deletes a content",
	Long: `Deletes a content. For example:
mim content delete --id="my-id"

or

mim content delete my-id

`,
	Run: func(cmd *cobra.Command, args []string) {
		server, token, err := login.ResolveCredentials()
		utils.HandleError(err)

		id, err := cmd.Flags().GetString("id")
		utils.HandleError(err)

		if len(args) > 0 {

			id = args[0]
		}

		if id == "" {
			pterm.Error.Println("You must provide an id")
			os.Exit(1)
		}

		confirm, err := cmd.Flags().GetBool("confirm")
		utils.HandleError(err)

		pterm.EnableDebugMessages()

		pterm.DefaultSection.Println("Deleting content " + server + "/content/" + id)

		if confirm {
			pterm.DefaultSection.Printf("Delete content with content id " + id + " on " + server + ", please type (y)es or (n)o and then press enter:")
			if utils.AskForConfirmation() {
				err = web.DeleteRequest(server, token, fmt.Sprintf("/content/%s", id))
				utils.HandleError(err)

				pterm.Success.Println("Deleted content")
				pterm.Println()
			} else {
				pterm.Println("Aborted!")
			}
		} else {
			err = web.DeleteRequest(server, token, fmt.Sprintf("/content/%s", id))
			utils.HandleError(err)

			pterm.Success.Println("Deleted content")
			pterm.Println()
		}

	},
	TraverseChildren: true,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}
		return getContentsCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp
	},
}
View Source
var ListCmd = &cobra.Command{
	Use:     "list",
	Aliases: []string{"ls"},
	Short:   "List all contents",
	Long: `List all contents. For example:
mim dataset list

`,
	Run: func(cmd *cobra.Command, args []string) {
		format := utils.ResolveFormat(cmd)
		if format != "term" {
			pterm.DisableOutput()
		}

		server, token, err := login.ResolveCredentials()
		utils.HandleError(err)

		pterm.EnableDebugMessages()

		pterm.DefaultSection.Println("Listing contents on " + server + "/content")

		contents, err := getContents(server, token)
		utils.HandleError(err)

		err = render(contents, format)
		utils.HandleError(err)
	},
	TraverseChildren: true,
}
View Source
var ShowCmd = &cobra.Command{
	Use:     "get",
	Aliases: []string{"show"},
	Short:   "Show a single content",
	Long: `Show a single content. For example:
mim content show --id="my-id"

or

mim content show my-id

`,
	Run: func(cmd *cobra.Command, args []string) {
		format := utils.ResolveFormat(cmd)
		if format != "term" {
			pterm.DisableOutput()
		}
		server, token, err := login.ResolveCredentials()
		utils.HandleError(err)

		id, err := cmd.Flags().GetString("id")
		utils.HandleError(err)

		if len(args) > 0 {

			id = args[0]
		}

		if id == "" {
			pterm.Error.Println("You must provide an id")
			os.Exit(1)
		}

		pterm.EnableDebugMessages()

		pterm.DefaultSection.Println("Describing content on " + server + "/content/" + id)

		content, err := getContent(server, token, id)
		utils.HandleError(err)

		renderContent(content, format)
		utils.HandleError(err)
	},
	TraverseChildren: true,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}
		return getContentsCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL