diff --git a/completion/license-tool.zsh b/completion/license-tool.zsh new file mode 100644 index 0000000..5b8dd05 --- /dev/null +++ b/completion/license-tool.zsh @@ -0,0 +1,27 @@ +#compdef license-tool + +_license-tool_files() { + # system dir + local system_dir="/usr/share/license-tool/" + for file in "${system_dir}"**(N); do + compadd -X "[system]" "${file#"${system_dir}"}" + done + + # user dir + if [[ -v XDG_CONFIG_HOME ]]; then + local user_dir="${XDG_CONFIG_HOME}/license-tool/" + else + local user_dir="${HOME}/.config/license-tool/" + fi + for file in "${user_dir}"**(N); do + compadd -X "[user]" "${file#"${user_dir}"}" + done +} + +_arguments -w \ + '-h[print help]' \ + '-l[list installed licenses]' \ + '-s[only search the system license directory]' \ + '-u[only search the user license directory]' \ + '-o[output file]:output:_files' \ + ':license:_license-tool_files' diff --git a/license-tool.cabal b/license-tool.cabal index da81842..1999a6c 100644 --- a/license-tool.cabal +++ b/license-tool.cabal @@ -1,4 +1,4 @@ -cabal-version: 2.2 +cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.38.1. -- @@ -6,11 +6,13 @@ cabal-version: 2.2 name: license-tool version: 0.1.0.0 +synopsis: Tool for generating LICENSE files description: Please see the README at +category: Development author: Alexander Rosenberg maintainer: zanderpkg@pm.me copyright: 2026 Alexander Rosenberg -license: BSD-3-Clause +license: GPL-3 license-file: LICENSE build-type: Simple extra-source-files: @@ -25,13 +27,11 @@ executable license-tool main-is: Main.hs other-modules: Paths_license_tool - autogen-modules: - Paths_license_tool hs-source-dirs: src ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 - , directory - , filepath + , directory >=1.3.8 && <1.4 + , filepath >=1.5.4 && <1.6 default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index a1e9a4f..af71820 100644 --- a/package.yaml +++ b/package.yaml @@ -1,27 +1,22 @@ name: license-tool version: 0.1.0.0 -license: BSD-3-Clause -author: "Alexander Rosenberg" -maintainer: "zanderpkg@pm.me" -copyright: "2026 Alexander Rosenberg" +license: GPL-3 +author: Alexander Rosenberg +maintainer: zanderpkg@pm.me +copyright: 2026 Alexander Rosenberg +synopsis: Tool for generating LICENSE files +category: Development extra-source-files: - README.md - licenses/* -# Metadata used when publishing your package -# synopsis: Short description of your package -# category: - -# To avoid duplicated efforts in documentation and dealing with the -# complications of embedding Haddock markup inside cabal files, it is -# common to point users to the README.md file. description: Please see the README at dependencies: - base >= 4.7 && < 5 - - directory - - filepath + - directory >= 1.3.8 && < 1.4 + - filepath >= 1.5.4 && < 1.6 ghc-options: - -Wall diff --git a/src/Main.hs b/src/Main.hs index fc6bcc6..17ade3f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -5,7 +5,7 @@ import Control.Monad import Data.Functor import Data.List (isInfixOf, isSuffixOf) import System.Directory (listDirectory) -import System.Environment (getArgs, getEnv) +import System.Environment (getArgs, getEnv, lookupEnv) import System.IO import System.IO.Error @@ -13,12 +13,12 @@ import System.IO.Error defaultOutfile :: String defaultOutfile = "LICENSE" +defaultUserLicenseDirName :: String +defaultUserLicenseDirName = "license-tool" + defaultSystemLicenseDir :: String defaultSystemLicenseDir = "/usr/share/license-tool" -defaultUserLicenseRelDir :: String -defaultUserLicenseRelDir = ".config/license-tool" - -- Argument parsing data SearchMode = SystemOnly | UserOnly | UserThenSystem @@ -71,8 +71,13 @@ normalizeDirectory :: String -> String normalizeDirectory s = if "/" `isSuffixOf` s then s else s ++ "/" userLicenseDir :: IO String -userLicenseDir = userHomeDir <&> (++ defaultUserLicenseRelDir) +userLicenseDir = xdgConfigHome <&> (++ defaultUserLicenseDirName) where + xdgConfigHome :: IO String + xdgConfigHome = + (lookupEnv "XDG_CONFIG_HOME") + >>= maybe userHomeDir (return . normalizeDirectory) + userHomeDir :: IO String userHomeDir = getEnv "HOME" <&> normalizeDirectory