#!/bin/bash
# dev/package/cli - package CLI

set -e

lib_load 'dev/package/load'


######
# Package CLI

package_cli_dispatch() { lib_cmd_dispatch package_cli "$@"; }

package_cli_usage() {
	cat <<USAGE
<cmd> ...
Package Commands:
	config				Prints the package configuration
	dist ...			Generates package distribution files
	version ...			Package version commands
	license ...			Package license commands
	release ...			Package release commands
	publish ...			Package publishing commands
	install ...			Package installation commands

Package Introspection Commands:
	sym ...				Package symbol commands
USAGE
}


######
# Package Symbol Commands

package_cli_sym() { cmd_dispatch "$@"; }

package_cli_sym_usage() {
	cat <<USAGE
...
Source Code Symbol Commands:
	all				Prints all global symbols
	conf [<file>+]			Prints tool/library setting symbols
	vars [<file>+]			Prints function symbols
	funcs [<file>+]			Prints function symbols

	rename <old> <new> [<suffix>]	Renames a symbol in all package files
USAGE
}

package_cli_sym_all() {
	package_cli_sym_vars
	package_cli_sym_funcs
	package_cli_sym_conf
}

package_cli_sym_vars() {
	lib_load 'dev/package/search'
	package_grep '^[a-z0-9_]+=' -nE | sed -e 's,^,$,' -e 's,=.*$,,'
}

package_cli_sym_funcs() {
	lib_load 'dev/package/search'
	package_grep '[a-z0-9_]+\(\)' -nE | sed -e 's,().*$,(),'
}

package_cli_sym_conf() {
	warn "unimplemented"
}

# package_cli_sym_rename() - Renames a package symbol ($1) to a new name ($2)
# and commits the changes on the current branch.
package_cli_sym_rename() {
	has_args 2 "$@"

	lib_load 'dev/package/edit'
	package_symbol_rename "$@"

	git_add $(package_files_sources)
	git_commit -m "rename symbol: $1 -> $2"
}


######
# Package Configuration and Distribution

package_cli_config() {
	lib_load 'dev/package/config'
	package_config "$@"
}

package_cli_dist() {
	lib_load 'dev/package/dist'
	package_dist "$@"
}


######
# Package Version CLI

package_cli_version() {
	lib_load 'dev/package/versions'
	if [ "$*" ]; then
		cmd_dispatch "$@"
	else
		package_version_read
	fi
}

package_cli_version_usage() {
	cat <<USAGE
[<cmd> ...]
Package Version Commands:
	[show]				Prints the package version
	bump (micro|minor|major)	Bumps package version and commit
	unbump				Drops the version bump commit at HEAD
	tag 				Creates a new version tag

Note: These are emergency commands.  Use 'package release' instead.
USAGE
}

package_cli_version_bump() { package_version_bump "$@"; }
package_cli_version_unbump() { package_version_unbump "$@"; }

package_cli_version_tag() { package_version_tag "$@"; }
package_cli_version_untag() { package_version_untag "$@"; }


######
# Package Releases

package_cli_release() {
	lib_load 'dev/package/release'
	cmd_dispatch "$@"
}

package_cli_release_usage() {
	cat <<USAGE
...
Package Wizard:
	wizard <type> <branch>		Runs the package release wizard.

Package Release Commands:
	(major|minor|micro)		Creates a new public release
	site-(major|minor|micro)	Creates a new site release

Low-Level Release Cmmmands:
	ready				Verifies the release is ready
	tag				Creates the new tag
	undo				Reverts a just-made release
USAGE
}

package_cli_release_wizard() {
	lib_load 'dev/package/wizard'
	package_wizard_release "$@"
}

package_cli_release_micro() { run package_release micro; }
package_cli_release_minor() { run package_release minor; }
package_cli_release_major() { run package_release major; }

package_cli_release_ready() {
	local not=''
	package_release_ready || not=' NOT'
	local func=app_echo
	[ -z "$not" ] || func=error
	$func "$PKG: package is$not ready to release"
}

package_cli_release_tag() { package_release_tag "$@"; }
package_cli_release_undo() { package_release_undo "$@"; }


######
# Package Publishing

package_cli_publish() {
	lib_load 'dev/package/publish'
	cmd_dispatch "$@"
}

package_cli_publish_usage() {
	cat <<USAGE
<cmd> [...]
Package Publishing Commands:
	wizard				Runs the publishing wizard
	release ...			Commands to publish releases

Repository Publishing Commands:
	master				Pushes to origin repository
	github				Pushes to GitHub repository
USAGE
}

package_cli_publish_wizard() {
	lib_load 'dev/package/wizard'
	package_publish_wizard "$@"
}

package_cli_publish_master() { package_publish_git_remote origin; }
package_cli_publish_github() { package_publish_git_remote github ; }


######
# Package Release Publishing

package_cli_publish_release() { cmd_dispatch "$@"; }

package_cli_publish_release_usage() {
	cat <<USAGE
<cmd> [...]
Package Release Publishing Commands:
	all <version> [<branch>]	Performs all publishing steps
	tarballs <version>		Pushes tarballs to release server
	docs <version>			Pushes documentation to release server
	installers <version>		Publishes package installers
	links <version>	[<branch>]	Updates symbolic links for <branch>
	announce <version>		Publishes a release announcement
USAGE
}

package_cli_publish_release_all() {
	package_publish_tarballs "$@"
	package_publish_docs "$@"
	package_publish_installers "$@"
	package_publish_links "$@"
	package_publish_announce "$@"
}

package_cli_publish_release_tarballs() { package_publish_tarballs "$@"; }
package_cli_publish_release_docs() { package_publish_docs "$@"; }
package_cli_publish_release_installer() { package_publish_installer "$@"; }
package_cli_publish_release_links() { package_publish_links "$@"; }
package_cli_publish_release_announce() { package_publish_announce "$@"; }


######
# Package Installation

package_cli_install() {
	lib_load 'dev/package/install'
	cmd_dispatch "$@"
}

package_cli_install_usage() {
	cat <<USAGE
<cmd>
Package Installation Commands:
	local <vers>			Installs the package locally
	remote <vers> <host>+		Installs on the remote host(s)
	script ...			Commands to generate installer scripts
USAGE
}

package_cli_install_local() { package_install_local "$@"; }
package_cli_install_remote() { package_install_remote "$@"; }


######
# Package Installer Scripts

package_cli_install_script() { cmd_dispatch "$@"; }

package_cli_install_script_usage() {
	cat <<USAGE
<cmd>
Package Installer Script Commands:
	local <vers> 			Prints local installer script
	remote <vers> 			Prints remote installer script
	network <vers> 			Prints network installer script
	complete <vers>			Prints all-in-one installer script
USAGE
}

package_cli_install_script_local() { package_install_script_local "$@"; }
package_cli_install_script_remote() { package_install_script_remote "$@"; }
package_cli_install_script_network() { package_install_script_net "$@"; }
package_cli_install_script_complete() { package_install_script_complete "$@"; }

View the Developer Guide Index

View the Reference Manual Index


Generated on Thu May 4 18:59:41 PDT 2017 by mcsh i7 v0.19.0.