From 035a3088d49e47281575088e25c7079eeb72120c Mon Sep 17 00:00:00 2001 From: Jon Carstens Date: Tue, 22 Dec 2020 10:39:50 -0700 Subject: [PATCH] Support XDG_DATA_HOME Resolves https://github.com/nerves-hub/nerves_hub_cli/issues/120 --- lib/nerves_hub_cli.ex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/nerves_hub_cli.ex b/lib/nerves_hub_cli.ex index c996537..a690652 100644 --- a/lib/nerves_hub_cli.ex +++ b/lib/nerves_hub_cli.ex @@ -10,6 +10,8 @@ defmodule NervesHubCLI do """ @type fwup_public_key_ref :: String.t() | atom() + defguard valid_home_dir(dir) when is_binary(dir) and dir != "" + @spec default_description() :: String.t() def default_description() do {:ok, hostname} = :inet.gethostname() @@ -20,10 +22,10 @@ defmodule NervesHubCLI do override_dir = Application.get_env(:nerves_hub_cli, :home_dir) || System.get_env("NERVES_HUB_HOME") - if override_dir == nil or override_dir == "" do - Path.expand("~/.nerves-hub") - else - override_dir + case {override_dir, System.get_env("XDG_DATA_HOME")} do + {dir, _} when valid_home_dir(dir) -> dir + {_, xdg} when valid_home_dir(xdg) -> Path.join(xdg, "nerves-hub") + _ -> Path.expand("~/.nerves-hub") end end