#!/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:
	dist ...			Package distribution commands
	version ...			Package version commands
	release ...			Package release commands
	publish ...			Package publishing commands
	install ...			Package installation commands

Package Introspection Commands:
	config ...			Package configuration 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 Release Cmmmands:
	wizard <type>			Creates a new package release
	create			Creates a new package release
	finish <type>			Finalizes the release

Low-Level Release Cmmmands:
	ready				Verifies the release is ready
	lock				Makes local release files read-only.
	unlock				Makes local release files writable.
	undo				Reverts a local release
USAGE
}

package_cli_release_wizard() { package_release_wizard "$@"; }
package_cli_release_create() { run package_release_create "$@"; }
package_cli_release_finish() { run package_release_finish "$@"; }
package_cli_release_undo() { package_release_undo "$@"; }

package_cli_release_lock() { package_release_unlock "$@"; }
package_cli_release_unlock() { package_release_unlock "$@"; }

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 Publishing

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

package_cli_publish_usage() {
	cat <<USAGE
<cmd> [...]
Package Publishing Commands:
	upload				Uploads all release artifacts
	finish [<branch>]		Finalizes the release

Release Upload Commands:
	tarballs [<version>]		Pushes tarballs to release server
	docs [<version>]		Pushes documentation to release server
	installers [<version>]		Publishes package installers

Release Finalization Commands:
	lock [<version>]		Locks uploaded release files
	links [<version>]		Updates symbolic links for <branch>
	announce [<version>]		Publishes a release announcement

Release Cleanup Commands:
	unlock [<version>]		Unlocks uploaded release files
	cleanup [<version>]		Removes uploads from a failed release
USAGE
}

package_cli_publish_upload() { package_publish_upload "$@"; }
package_cli_publish_finish() { package_publish_finish "$@"; }


package_cli_publish_tarballs() { package_publish_tarballs "$@"; }
package_cli_publish_docs() { package_publish_docs "$@"; }
package_cli_publish_installers() { package_publish_installers "$@"; }

package_cli_publish_links() { package_publish_links "$@"; }
package_cli_publish_announce() { package_publish_announce "$@"; }

package_cli_publish_lock() { package_publish_lock "$@"; }
package_cli_publish_unlock() { package_publish_unlock "$@"; }
package_cli_publish_cleanup() { package_publish_abort "$@"; }


######
# 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 Tue Jul 4 17:00:33 PDT 2017 by mcsh d14 v0.21.0.