Skip to content

Commit

Permalink
Merge pull request #423 from stgraber/main
Browse files Browse the repository at this point in the history
CLI fixes
  • Loading branch information
hallyn committed Jan 23, 2024
2 parents e569070 + 36443d5 commit 0523f5a
Show file tree
Hide file tree
Showing 12 changed files with 1,121 additions and 1,086 deletions.
8 changes: 8 additions & 0 deletions cmd/incus/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ func (c *cmdAliasList) Run(cmd *cobra.Command, args []string) error {
data = append(data, []string{k, v})
}

// Apply default entries.
for k, v := range defaultAliases {
_, ok := conf.Aliases[k]
if !ok {
data = append(data, []string{k, v})
}
}

sort.Sort(cli.SortColumnsNaturally(data))

header := []string{
Expand Down
15 changes: 12 additions & 3 deletions cmd/incus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ func main() {
`Command line client for Incus
All of Incus's features can be driven through the various commands below.
For help with any of those, simply call them with --help.`))
For help with any of those, simply call them with --help.
Custom commands can be defined through aliases, use "incus alias" to control those.`))
app.SilenceUsage = true
app.SilenceErrors = true
app.CompletionOptions = cobra.CompletionOptions{HiddenDefaultCmd: true}
Expand Down Expand Up @@ -329,15 +331,22 @@ func (c *cmdGlobal) PreRun(cmd *cobra.Command, args []string) error {
var configDir string
if os.Getenv("INCUS_CONF") != "" {
configDir = os.Getenv("INCUS_CONF")
} else if os.Getenv("HOME") != "" {
} else if os.Getenv("HOME") != "" && util.PathExists(os.Getenv("HOME")) {
configDir = path.Join(os.Getenv("HOME"), ".config", "incus")
} else {
user, err := user.Current()
if err != nil {
return err
}

configDir = path.Join(user.HomeDir, ".config", "incus")
if util.PathExists(user.HomeDir) {
configDir = path.Join(user.HomeDir, ".config", "incus")
}
}

// If no homedir could be found, treat as if --force-local was passed.
if configDir == "" {
c.flagForceLocal = true
}

c.confPath = os.ExpandEnv(path.Join(configDir, "config.yml"))
Expand Down
Loading

0 comments on commit 0523f5a

Please sign in to comment.