File ghc-optparse-applicative.spec of Package ghc-optparse-applicative

#
# spec file for package ghc-optparse-applicative
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%global pkg_name optparse-applicative
%bcond_with tests
Name:           ghc-%{pkg_name}
Version:        0.13.1.0
Release:        0
Summary:        Utilities and combinators for parsing command line options
License:        BSD-3-Clause
Group:          Development/Languages/Other
Url:            https://hackage.haskell.org/package/%{pkg_name}
Source0:        https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz
BuildRequires:  ghc-Cabal-devel
BuildRequires:  ghc-ansi-wl-pprint-devel
BuildRequires:  ghc-process-devel
BuildRequires:  ghc-rpm-macros
BuildRequires:  ghc-transformers-compat-devel
BuildRequires:  ghc-transformers-devel
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if %{with tests}
BuildRequires:  ghc-QuickCheck-devel
%endif

%description
Here is a simple example of an applicative option parser:

' data Sample = Sample   { hello :: String   , quiet :: Bool
}

sample :: Parser Sample sample = Sample &#x20; <$> strOption &#x20; ( long
"hello" &#x20; <> metavar "TARGET" &#x20; <> help "Target for the greeting" )
&#x20; <*> switch &#x20; ( long "quiet" &#x20; <> help "Whether to be quiet" )
'

The parser is built using applicative style starting from a set of basic
combinators. In this example, 'hello' is defined as an 'option' with a 'String'
argument, while 'quiet' is a boolean 'flag' (called 'switch').

A parser can be used like this:

' greet :: Sample -> IO () greet (Sample h False) = putStrLn $ "Hello, " ++ h
greet _ = return ()

main :: IO () main = execParser opts >>= greet &#x20; where &#x20; opts = info
(helper <*> sample) &#x20; ( fullDesc &#x20; <> progDesc "Print a greeting for
TARGET" &#x20; <> header "hello - a test for optparse-applicative" ) '

The 'greet' function is the entry point of the program, while 'opts' is a
complete description of the program, used when generating a help text.
The 'helper' combinator takes any parser, and adds a 'help' option to it (which
always fails).

The 'hello' option in this example is mandatory (since it doesn't have a
default value), so running the program without any argument will display a help
text:

>hello - a test for optparse-applicative > >Usage: hello --hello TARGET
[--quiet] > Print a greeting for TARGET > >Available options: > -h,--help Show
this help text > --hello TARGET Target for the greeting > --quiet Whether to be
quiet

containing a short usage summary, and a detailed list of options with
descriptions.

%package devel
Summary:        Haskell %{pkg_name} library development files
Group:          Development/Libraries/Other
Requires:       %{name} = %{version}-%{release}
Requires:       ghc-compiler = %{ghc_version}
Requires(post): ghc-compiler = %{ghc_version}
Requires(postun): ghc-compiler = %{ghc_version}

%description devel
This package provides the Haskell %{pkg_name} library development
files.

%prep
%setup -q -n %{pkg_name}-%{version}

%build
%ghc_lib_build

%install
%ghc_lib_install

%check
%cabal_test

%post devel
%ghc_pkg_recache

%postun devel
%ghc_pkg_recache

%files -f %{name}.files
%defattr(-,root,root,-)
%doc LICENSE

%files devel -f %{name}-devel.files
%defattr(-,root,root,-)
%doc CHANGELOG.md README.md

%changelog
openSUSE Build Service is sponsored by