Skip to content

Commit

Permalink
add delete functionality even though it's hacky
Browse files Browse the repository at this point in the history
  • Loading branch information
bitte-ein-bit committed Jul 3, 2024
1 parent 93d49f1 commit 54708c3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func init() {
cmdAppsCreate.AddCommand(cmdAppsCreateOneLogin)
cmdAppsCreate.AddCommand(cmdAppsCreateOkta)
cmdApps.AddCommand(cmdAppsSelect)
cmdApps.AddCommand(cmdAppsDelete)
}

var cmdApps = &cobra.Command{
Expand Down Expand Up @@ -229,3 +230,27 @@ var cmdAppsSelect = &cobra.Command{
}
},
}

var cmdAppsDelete = &cobra.Command{
Use: "delete [app name]",
Short: "Delete an app",
Long: "Delete an app from the config file.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
app := args[0]

if exists := viper.Get("apps." + app); exists == nil {
log.Log.Fatalf("App '%s' doesn't exist", app)
}

// Delete app
delete(viper.Get("apps").(map[string]interface{}), app)

// Write config to file
err := viper.WriteConfig()
if err != nil {
log.Log.Fatalf("Error writing config: %v", err)
}
log.Log.Printf("App '%s' deleted from config file", app)
},
}

0 comments on commit 54708c3

Please sign in to comment.