#compdef se

local state line

_arguments -C -A "-v" -A "--version" \
	'(- 1 *)'{-v,--version}'[print version number and exit]' \
	'1: :->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-images[Build ebook cover and titlepage images in a Standard Ebook source directory.]" \
			"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.]" \
			"dec2roman[Convert a decimal number to a Roman numeral.]" \
			"extract-ebook[Extract an EPUB, MOBI, or AZW3 ebook.]" \
			"find-mismatched-diacritics[Find words with mismatched diacritics in Standard Ebook source directories.]" \
			"help[List available SE commands.]" \
			"hyphenate[Insert soft hyphens at syllable breaks in an XHTML file.]" \
			"interactive-sr[Use Vim to perform an interactive search and replace on a list of files.]" \
			"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.]" \
			"print-manifest[Print the <manifest> element for the given Standard Ebooks source directory to standard output, for use in that directory’s content.opf.]" \
			"print-spine[Print the <spine> element for the given Standard Ebooks source directory to standard output, for use in that directory’s content.opf.]" \
			"print-title[Print the expected value for an XHTML file’s <title> element.]" \
			"print-toc[Build a table of contents for an SE source directory and print to stdout.]" \
			"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.]" \
			"reorder-endnotes[Increment the specified endnote and all following endnotes by 1.]" \
			"roman2dec[Convert a Roman numeral to a decimal number.]" \
			"semanticate[Apply some scriptable semantics rules from the Standard Ebooks semantics manual.]" \
			"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.]"
		;;
	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 --kindle is also specified and epubcheck fails, 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]' \
					{-t,--covers}'[output the cover and a cover thumbnail]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_directories'
				;;
			build-images)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_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-common}'[include commonly-excluded SE 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-url}'[the URL of the Project Gutenberg ebook to download]' \
					{-r,--translator}'[the translator of the ebook]' \
					{-t,--title}'[the title of the ebook]'
				;;
			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-diacritics)
				_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-sr)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					'*: :_files'
				;;
			lint)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-n,--no-colors}'[don’t use color or hyperlinks in output]' \
					{-p,--plain}'[print plain output]' \
					{-s,--skip-lint-ignore}'[ignore rules in se-lint-ignore.xml file]' \
					{-v,--verbose}'[increase output verbosity]' \
					{-w,--wrap}'[force lines to wrap at this number of columns instead of auto-wrapping]' \
					'*: :_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'
				;;
			print-manifest)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-i,--in-place}'[overwrite the <manifest> element in content.opf instead of printing to stdout]' \
					'*: :_directories'
				;;
			print-spine)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-i,--in-place}'[overwrite the <spine> element in content.opf instead of printing to stdout]' \
					'*: :_directories'
				;;
			print-title)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-i,--in-place}'[replace the file’s <title> element instead of printing to stdou]' \
					'*: :_files -g \*.xhtml'
				;;
			print-toc)
				_arguments -s \
					{-h,--help}'[show a help message and exit]' \
					{-i,--in-place}'[overwrite the existing toc.xhtml file instead of printing to stdout]' \
					'*: :_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]' \
					{-v,--verbose}'[increase output verbosity]' \
					'*: :_directories'
				;;
			reorder-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'
				;;
			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'
				;;
			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, 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 SE ebooks, like the ToC and colophon]' \
					'*: :_files -g \*.\(htm\|html\|xhtml\)'
				;;
		esac
		;;
esac

return 0
