cli-setup (empty) → 0.1.0.0
raw patch · 7 files changed
+119/−0 lines, 7 filesdep +basedep +directorydep +processsetup-changed
Dependencies added: base, directory, process
Files
- LICENSE +11/−0
- README.md +5/−0
- Setup.hs +2/−0
- cabal.project.local +7/−0
- cli-setup.cabal +39/−0
- src/Distribution/CommandLine.hs +46/−0
- stack.yaml +9/−0
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright Vanessa McHale (c) 2018++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,5 @@+# cli-setup++## Installation++## Configuration
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cabal.project.local view
@@ -0,0 +1,7 @@+constraints: cli-setup +development+with-compiler: ghc-8.2.2+tests: True+benchmarks: True+documentation: True+haddock-hoogle: True+haddock-internal: True
+ cli-setup.cabal view
@@ -0,0 +1,39 @@+name: cli-setup+version: 0.1.0.0+synopsis: Helper setup scripts for packaging command-line tools.+description: Provides functions to set up manpages and shell completions. Intended to be used in the @Setup.hs@ module.+homepage: https://github.com/vmchale/cli-setup#readme+license: BSD3+license-file: LICENSE+author: Vanessa McHale+maintainer: vamchale@gmail.com+copyright: Copyright: (c) 2018 Vanessa McHale+category: Development, Command Line Tools+build-type: Simple+extra-doc-files: README.md+extra-source-files: stack.yaml+ , cabal.project.local+cabal-version: >=1.18++Flag development {+ Description: Enable `-Werror`+ manual: True+ default: False+}++library+ hs-source-dirs: src+ exposed-modules: Distribution.CommandLine+ build-depends: base >= 4.8 && < 5+ , directory+ , process+ default-language: Haskell2010+ if flag(development)+ ghc-options: -Werror+ if impl(ghc >= 8.0)+ ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat+ ghc-options: -Wall++source-repository head+ type: darcs+ location: https://hub.darcs.net/vmchale/cli-setup
+ src/Distribution/CommandLine.hs view
@@ -0,0 +1,46 @@+module Distribution.CommandLine+ ( writeManpages+ , writeBashCompletions+ , setManpath+ ) where++import Control.Monad (unless, void)+import System.Directory (createDirectoryIfMissing)+import System.Environment (lookupEnv)+import System.Process (readCreateProcessWithExitCode, shell)++setManpath :: IO ()+setManpath = do+ home <- lookupEnv "HOME"+ case home of+ Just x -> do+ let bashRc = x ++ "/.bashrc"+ config <- readFile bashRc+ unless ("#manpath updated by cli-setup" `elem` lines config)+ (appendFile bashRc "\n#manpath updated by cli-setup\nexport MANPATH=~/.local/share:$MANPATH\n" >>+ void (readCreateProcessWithExitCode (shell $ "MANPATH=" ++ x ++ "/.local/share mandb") ""))+ Nothing -> pure ()++writeManpages :: FilePath -- ^ Source File+ -> FilePath -- ^ Manpage file name+ -> IO ()+writeManpages p p' = do+ home <- lookupEnv "HOME"+ case home of+ Just x -> do+ let manPath = x ++ "/.local/share/man/man1"+ createDirectoryIfMissing True manPath+ writeFile (manPath ++ "/" ++ p') =<< readFile p+ Nothing -> pure ()++writeBashCompletions :: String -- ^ Executable name+ -> IO ()+writeBashCompletions exeName = do+ home <- lookupEnv "HOME"+ case home of+ Just x -> do+ let bashRc = x ++ "/.bashrc"+ config <- readFile bashRc+ unless (("# Added for " ++ exeName) `elem` lines config)+ (appendFile bashRc ("\n# Added for " ++ exeName ++ "\neval \"$(" ++ exeName ++ " --bash-completion-script " ++ exeName ++ ")\"\n"))+ Nothing -> pure ()
+ stack.yaml view
@@ -0,0 +1,9 @@+---+resolver: lts-10.3+packages:+ - '.'+extra-deps: []+flags:+ cli-setup:+ development: false+extra-package-dbs: []