#compdef se

local state line

_arguments -C \
	'(- :)'{-h,--help}'[show a help message and exit]' \
	'(-p --plain)'{-p,--plain}'[print plain text output, without tables or formatting]' \
	'(- :)'{-v,--version}'[print version number and exit]' \
	'(-): :->cmds' \
	'(-)*:: :->args'

case $state in
	cmds)
		_values "se command" \
			"british2american[Try to convert British quote style to American quote style.]" \
			"build[Build an ebook from a Standard Ebook source directory.]" \
			"build-ids[Change ID attributes for non-sectioning content to their expected values across the entire ebook. IDs must be globally unique and correctly referenced, and the ebook spine must be complete.]" \
			"build-images[Build ebook cover and titlepage images in a Standard Ebook source directory.]" \
			"build-manifest[Generate the <manifest> element for the given Standard Ebooks source directory and write it to the ebook’s metadata file.]" \
			"build-spine[Generate the <spine> element for the given Standard Ebooks source directory and write it to the ebook’s metadata file.]" \
			"build-title[Generate the title of an XHTML file based on its headings and update the file’s <title> element.]" \
			"build-toc[Generate the table of contents for the ebook’s source directory and update the ToC file.]" \
			"clean[Prettify and canonicalize individual XHTML or SVG files.]" \
			"compare-versions[Render and compare XHTML files in an ebook repository.]" \
			"create-draft[Create a skeleton of a new Standard Ebook.]" \
			"css-select[Print the results of a CSS selector evaluated against a set of XHTML files.]" \
			"dec2roman[Convert a decimal number to a Roman numeral.]" \
			"extract-ebook[Extract an EPUB, MOBI, or AZW3 ebook.]" \
			"find-mismatched-dashes[Find words with mismatched dashes in a set of XHTML files.]" \
			"find-mismatched-diacritics[Find words with mismatched diacritics in a set of XHTML files.]" \
			"find-unusual-characters[Find characters outside a nominal expected range in a set of XHTML files.]" \
			"help[List available S.E. commands.]" \
			"hyphenate[Insert soft hyphens at syllable breaks in an XHTML file.]" \
			"interactive-replace[Perform an interactive search and replace on a list of files using Python-flavored regex. The view is scrolled using the arrow keys, with alt to scroll by page in any direction. Basic Emacs (default) or Vim style navigation is available. The following actions are possible: (y) Accept replacement. (n) Reject replacement. (a) Accept all remaining replacements in this file. (r) Reject all remaining replacements in this file. (c) Center on match. (q) Save this file and quit.]" \
			"lint[Check for various Standard Ebooks style errors.]" \
			"make-url-safe[Make a string URL-safe.]" \
			"modernize-spelling[Modernize spelling of some archaic words, and replace words that may be archaically compounded with a dash to a more modern spelling.]" \
			"prepare-release[Calculate work word count, insert release date if not yet set, and update modified date and revision number.]" \
			"recompose-epub[Recompose a Standard Ebooks source directory into a single HTML5 file, and print to standard output.]" \
			"renumber-endnotes[Renumber all endnotes and noterefs sequentially from the beginning.]" \
			"roman2dec[Convert a Roman numeral to a decimal number.]" \
			"semanticate[Apply some scriptable semantics rules from the Standard Ebooks semantics manual.]" \
			"shift-endnotes[Increment the specified endnote and all following endnotes by 1 or a specified amount.]" \
			"shift-illustrations[Increment the specified illustration and all following illustrations by 1 or a specified amount.]" \
			"split-file[Split an XHTML file into many files.]" \
			"titlecase[Convert a string to titlecase.]" \
			"typogrify[Apply some scriptable typography rules from the Standard Ebooks typography manual to a Standard Ebook source directory.]" \
			"unicode-names[Display Unicode code points, descriptions, and links to more details for each character in a string.]" \
			"version[Print the version number and exit.]" \
			"word-count[Count the number of words in an HTML file and optionally categorize by length.]" \
			"xpath[Print the results of an xpath expression evaluated against a set of XHTML files. The default namespace is removed.]"
		;;
	args)
		case $line[1] in
			british2american)
				_arguments -s \
					{-f,--force}'[force conversion of quote style]' \
					{-h,--help}'[show a help message and exit]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_files -g \*.xhtml'
				;;
			build)
				_arguments -s \
					{-b,--kobo}'[also build a .kepub.epub file for Kobo]' \
					{-c,--check}'[use epubcheck to validate the compatible .epub file; if Ace is installed, also validate using Ace; if --kindle is also specified and epubcheck or Ace fail, don’t create a Kindle file]' \
					{-h,--help}'[show a help message and exit]' \
					{-k,--kindle}'[also build an .azw3 file for Kindle]' \
					{-o,--output-dir}'=[a directory to place output files in; will be created if it doesn’t exist]: :_directories' \
					{-p,--proof}'[insert additional CSS rules that are helpful for proofreading; output filenames will end in .proof]' \
					{-v,--verbose}'[increase output verbosity]' \
					{-y,--check-only}'[run tests used by --check but don’t output any ebook files and exit after checking]' \
					'*: :_directories'
				;;
			build-ids)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_directories'
				;;
			build-images)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_directories'
				;;
			build-manifest)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-s,--stdout}'[print to stdout instead of writing to the metadata file]' \
					'*: :_directories'
				;;
			build-spine)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-s,--stdout}'[print to stdout instead of writing to the metadata file]' \
					'*: :_directories'
				;;
			build-title)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-n,--no-newline}'[with --stdout, don’t end output with a newline]' \
					{-s,--stdout}'[print to stdout intead of writing to the file]' \
					'*: :_files -g \*.xhtml'
				;;
			build-toc)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-s,--stdout}'[print to stdout intead of writing to the ToC file]' \
					'*: :_directories'
				;;
			clean)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_files -g \*.\(svg\|xhtml\)'
				;;
			compare-versions)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-i,--include-se-files}'[include commonly-excluded S.E. files like imprint, titlepage, and colophon]' \
					{-n,--no-images}'[don’t copy diff images to the current working directory in case of difference]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_directories'
				;;
			create-draft)
				_arguments -s \
					{-a,--author}'[the author of the ebook]' \
					{-e,--email}'[use this email address as the main committer for the local Git repository]' \
					{-h,--help}'[show a help message and exit]' \
					{-i,--illustrator}'[the illustrator of the ebook]' \
					{-o,--offline}'[create draft without network access]' \
					{-p,--pg-id}'[the Project Gutenberg ID number of the ebook to download]' \
					{-r,--translator}'[the translator of the ebook]' \
					{-t,--title}'[the title of the ebook]' \
					{-w,--white-label}'[create a generic epub skeleton without S.E. branding]' \
					{-v,--verbose}'[increase output verbosity]'
				;;
			css-select)
				_arguments -s \
					{-f,--only-filenames}'[only output filenames of files that contain matches, not the matches themselves]' \
					{-h,--help}'[show a help message and exit]' \
					'*: :_files -g \*.xhtml'
				;;
			dec2roman)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-n,--no-newline}'[don’t end output with a newline]'
				;;
			extract-ebook)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-o,--output-dir}'=[a directory to place output files in; will be created if it doesn’t exist]: :_directories' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_files -g \*.\(mobi\|azw3\|epub\)'
				;;
			find-mismatched-dashes)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					'*: :_files -g \*.xhtml'
				;;
			find-mismatched-diacritics)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					'*: :_files -g \*.xhtml'
				;;
			find-unusual-characters)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					'*: :_files -g \*.xhtml'
				;;
			help)
				;;
			hyphenate)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-i,--ignore-h-tags}'[don’t add soft hyphens to text in <h1-6> tags]' \
					{-l,--language}'specify the language for the XHTML files; if unspecified, defaults to the `xml:lang` or `lang` attribute of the root <html> element' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_files -g \*.xhtml'
				;;
			interactive-replace)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-i,--ignore-case}'[ignore case when matching; equivalent to regex.IGNORECASE]' \
					{-m,--multiline}'[make `^` and `$` consider each line; equivalent to regex.MULTILINE]' \
					{-d,--dot-all}'[make `.` match newlines; equivalent to regex.DOTALL]' \
					{-v,--vim}'[use basic Vim-like navigation shortcuts]' \
					'*: :_files'
				;;
			lint)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-a,--allow}'[if an se-lint-ignore.xml file is present, allow these specific codes to be raised by lint]' \
					{-s,--skip-lint-ignore}'[ignore all rules in the se-lint-ignore.xml file]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_directories'
				;;
			make-url-safe)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-n,--no-newline}'[don’t end output with a newline]'
				;;
			modernize-spelling)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-n,--no-hyphens}'[don’t modernize hyphenation]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_files -g \*.xhtml'
				;;
			prepare-release)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-r,--no-revision}'[don’t increment the revision number]' \
					{-w,--no-word-count}'[don’t calculate word count]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_directories'
				;;
			recompose-epub)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-o,--output}'=[a file to write output to instead of printing to standard output]: :_files' \
					'*: :_files -g \*.xhtml' \
					{-x,--xhtml}'[output XHTML instead of HTML5]' \
					{-e,--extra-css-file}'=[the path to an additional CSS file to include after any CSS files in the epub]: :_files'
				;;
			renumber-endnotes)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-b,--brute-force}'[renumber without checking that noterefs and endnotes match; may result in endnotes with empty backlinks or noterefs without matching endnotes]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_directories'
				;;
			roman2dec)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-n,--no-newline}'[don’t end output with a newline]'
				;;
			semanticate)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_files -g \*.xhtml'
				;;
			shift-endnotes)
				_arguments -s \
					{-d,--decrement}'[decrement the target endnote number and all following endnotes]' \
					{-h,--help}'[show a help message and exit]' \
					{-i,--increment}'[increment the target endnote number and all following endnotes]' \
					'*: :_directories'
				;;
			split-file)
				_arguments -s \
					{-f,--filename-format}'[a format string for the output files; `%n` is replaced with the current chapter number; defaults to `chapter-%n.xhtml`]' \
					{-h,--help}'[show a help message and exit]' \
					{-s,--start-at}'[start numbering chapters at this number, instead of at 1]' \
					{-t,--template-file}'[a file containing an XHTML template to use for each chapter; the string `NUMBER` is replaced by the chapter number, the string `NUMERAL` is replaced by the chapter Roman numeral, and the string `TEXT` is replaced by the chapter body]' \
					'*: :_files -g \*.\(htm\|html\|xhtml\)'
				;;
			titlecase)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-n,--no-newline}'[don’t end output with a newline]'
				;;
			typogrify)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-n,--no-quotes}'[don’t convert to smart quotes before doing other adjustments]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_files -g \*.xhtml'
				;;
			unicode-names)
				_arguments -s \
					{-h,--help}'[show a help message and exit]'
				;;
			version)
				;;
			word-count)
				_arguments -s \
					{-c,--categorize}'[include length categorization in output]' \
					{-h,--help}'[show a help message and exit]' \
					{-p,--ignore-pg-boilerplate}'[attempt to ignore Project Gutenberg boilerplate headers and footers before counting]' \
					{-x,--exclude-se-files}'[exclude some non-bodymatter files common to S.E. ebooks, like the ToC and colophon]' \
					'*: :_files -g \*.\(htm\|html\|xhtml\)'
				;;
			xpath)
				_arguments -s \
					{-f,--only-filenames}'[only output filenames of files that contain matches, not the matches themselves]' \
					{-h,--help}'[show a help message and exit]' \
					'*: :_files -g \*.xhtml'
				;;
			unicode-names)
		esac
		;;
esac

return 0
