2026-03-26 12:48:47 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"axolotl/db"
|
|
|
|
|
"axolotl/output"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var aliasList bool
|
|
|
|
|
|
|
|
|
|
var aliasCmd = &cobra.Command{
|
2026-03-27 02:11:46 +01:00
|
|
|
Use: "alias [name] [command]", Short: "Manage aliases", Args: cobra.MaximumNArgs(2),
|
2026-03-26 12:48:47 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
d, err := db.GetDB()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-03-27 02:11:46 +01:00
|
|
|
w := cmd.OutOrStdout()
|
|
|
|
|
|
|
|
|
|
if aliasList || len(args) == 0 {
|
|
|
|
|
if aliases, err := d.ListAliases(); err == nil {
|
|
|
|
|
output.PrintAliases(w, aliases, jsonFlag)
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if len(args) == 1 {
|
2026-03-27 02:11:46 +01:00
|
|
|
if a, err := d.GetAlias(args[0]); err != nil {
|
|
|
|
|
fmt.Fprintln(os.Stderr, "alias not found:", args[0])
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Println(a.Command)
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := d.SetAlias(args[0], args[1]); err != nil {
|
2026-03-27 02:11:46 +01:00
|
|
|
fmt.Fprintln(os.Stderr, "failed to set alias:", err)
|
|
|
|
|
} else {
|
|
|
|
|
output.PrintAction(w, "Alias set", args[0], false)
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
rootCmd.AddCommand(aliasCmd)
|
2026-03-27 02:11:46 +01:00
|
|
|
aliasCmd.Flags().BoolVar(&aliasList, "list", false, "")
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|