mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-01-13 21:31:03 +00:00
feat: documentation and cleanup command
This commit is contained in:
parent
27d4e3240e
commit
c9ab40b539
16 changed files with 394 additions and 148 deletions
|
|
@ -1,40 +1,43 @@
|
|||
/*
|
||||
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/apricote/hcloud-upload-image/hcloudimages/contextlogger"
|
||||
)
|
||||
|
||||
// cleanupCmd represents the cleanup command
|
||||
var cleanupCmd = &cobra.Command{
|
||||
Use: "cleanup",
|
||||
Short: "A brief description of your command",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
Short: "Remove any temporary resources that were left over",
|
||||
Long: `If the upload fails at any point, there might still exist a server or
|
||||
ssh key in your Hetzner Cloud project. This command cleans up any resources
|
||||
that match the label "apricote.de/created-by=hcloud-upload-image".
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("cleanup called")
|
||||
If you want to see a preview of what would be removed, you can use the official hcloud CLI and run:
|
||||
|
||||
$ hcloud server list -l apricote.de/created-by=hcloud-upload-image
|
||||
$ hcloud ssh-key list -l apricote.de/created-by=hcloud-upload-image
|
||||
|
||||
This command does not handle any parallel executions of hcloud-upload-image
|
||||
and will remove in-use resources if called at the same time.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
logger := contextlogger.From(ctx)
|
||||
|
||||
err := client.CleanupTempResources(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to clean up temporary resources: %w", err)
|
||||
}
|
||||
|
||||
logger.InfoContext(ctx, "Successfully cleaned up all temporary resources!")
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(cleanupCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// cleanupCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// cleanupCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue