\documentclass[a4paper,oneside]{book}
\newenvironment{abstract}{}{}
\usepackage{noweb}
% Needed to relax penalty for breaking code chunks across pages, otherwise 
% there might be a lot of space following a code chunk.
\def\nwendcode{\endtrivlist \endgroup}
\let\nwdocspar=\smallbreak

\usepackage[hyphens]{url}
\usepackage{hyperref}
\usepackage{authblk}

\input{preamble.tex}

\title{%
  Canvas LMS: a command line interface
}
\author{%
  Daniel Bosk
}
\affil{%
  KTH EECS
}

\begin{document}
\frontmatter
\maketitle

\vspace*{\fill}
\VerbatimInput{../LICENSE}
\clearpage

\begin{abstract}
  \input{abstract.tex}
\end{abstract}
\clearpage


\tableofcontents
\clearpage

\mainmatter


\chapter{Introduction}

This is the documentation of the \texttt{canvaslms} Python package and the 
\texttt{canvaslms} command.
It provides a command-line interface for the Canvas LMS\@.

The command comes as a PyPI package.
It can be installed by running:
\begin{minted}{text}
  python3 -m pip install canvaslms
\end{minted}
Then you can use \texttt{canvaslms -h} for further usage instructions.

Some subcommands use the \texttt{pandoc} command\footnote{%
  URL: \url{https://pandoc.org/installing.html}.
}.
You will have to install that command manually.


\section{For contributors}

The package is divided into modules.
The \mintinline{python}|cli| module provides the base for the command and it uses the 
other modules.
There is a module for each subcommand.
Each such module must provide a function~\mintinline{python}|add_command| which takes 
an \mintinline{python}|argparse| (sub)parser as an argument.
\begin{minted}{python}
  def add_command(subp):
    command_parser = subp.add_parser("command", ...)
    command_parser.set_defaults(func=command_function)
\end{minted}
The subcommand must add the function~\mintinline{python}|command_function| which 
takes three arguments:
\begin{enumerate}
  \item \mintinline{python}|config|, a dictionary with the configuration data.
  \item \mintinline{python}|canvas|, a \mintinline{python}|canvasapi| object.
  \item \mintinline{python}|args|, the arguments parsed by 
    \mintinline{python}|argparse|.
\end{enumerate}
Something along these lines:
\begin{minted}{python}
def command_function(config, canvas, args):
  # process the args and do its thing
\end{minted}


%%% THE SOURCES %%%

\part{Some hacks}

\input{../src/canvaslms/hacks/canvasapi.tex}

\part{The command-line interface}

\input{../src/canvaslms/cli/cli.tex}
\input{../src/canvaslms/cli/login.tex}
\input{../src/canvaslms/cli/courses.tex}
\input{../src/canvaslms/cli/users.tex}
\input{../src/canvaslms/cli/assignments.tex}
\input{../src/canvaslms/cli/submissions.tex}
\input{../src/canvaslms/cli/grade.tex}


\printbibliography
\end{document}
