Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI fixes #423

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading