From 460fdd57f8fc4561a83482c2d0d8df1abf5a470b Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Fri, 21 Feb 2014 19:30:18 -0300 Subject: [PATCH] Add doc function --- README.md | 20 ++++++++++++++++++++ kickstart/recipes/kickstart/profile.sh | 12 ++++++------ lib/kickstart-doc | 12 ++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100755 lib/kickstart-doc diff --git a/README.md b/README.md index 203a528..a3ff49a 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,26 @@ Using alternate ssh port kickstart bootstrap "-p 2222 vagrant@vagrant" ``` +#### doc +Show documentation for a kickstart function + +```bash +kickstart doc [function name] +``` + +##### Example +List all documented functions + +```bash +kickstart doc +``` + +Show documentation for a function + +```bash +kickstart doc kickstart.os +``` + ### Thanks This project was inspired on [sunzi](https://github.com/kenn/sunzi) diff --git a/kickstart/recipes/kickstart/profile.sh b/kickstart/recipes/kickstart/profile.sh index 0798ae9..e13dd74 100644 --- a/kickstart/recipes/kickstart/profile.sh +++ b/kickstart/recipes/kickstart/profile.sh @@ -2,7 +2,7 @@ kickstart.profile.add_to_profile() { local file=$1 [ ! -f files/$file ] && kickstart.info "File files/$file not found" && exit 1 - local profile_d=`kickstart.profile.profile.d.location` + local profile_d=`kickstart.profile.location.profile_d` mkdir -p $profile_d cp files/$file $profile_d/$file @@ -11,11 +11,6 @@ kickstart.profile.add_to_profile() { kickstart.os.is Mac && kickstart.profile.source_on_configuration_file $file $profile_d `kickstart.profile.location.bash` } -kickstart.profile.profile.d.location() { - kickstart.os.is Ubuntu && echo /etc/profile.d - kickstart.os.is Mac && echo ~/.profile.d -} - kickstart.profile.source_on_configuration_file() { local file=$1 local profile_d=$2 @@ -23,6 +18,11 @@ kickstart.profile.source_on_configuration_file() { grep -q $file $configuration 2>/dev/null || ( echo "[[ -f $profile_d/$file ]] && source $profile_d/$file" >> $configuration ) } +kickstart.profile.location.profile_d() { + kickstart.os.is Ubuntu && echo /etc/profile.d + kickstart.os.is Mac && echo ~/.profile.d +} + kickstart.profile.location.zsh() { [ `whoami` = root ] && echo /etc/zshenv || echo ~/.zshenv } diff --git a/lib/kickstart-doc b/lib/kickstart-doc new file mode 100755 index 0000000..7eef3ee --- /dev/null +++ b/lib/kickstart-doc @@ -0,0 +1,12 @@ +#!/bin/bash + +list() { + root_dir=`kickstart root-dir` + find $root_dir/docs -type f | sed -e 's/.md$//' | cut -c `wc -c <<<$root_dir/docs/`- | tr '/' '.' +} + +show() { + cat `kickstart root-dir`/docs/$(echo $1 | tr '.' '/').md +} + +[ -z "$1" ] && list || show $1