#!/usr/bin/env ruby require 'fileutils' require 'dyndoc/init/home' dyndoc_home = Dyndoc.home #p Dyndoc.home lib_dir = ENV["DYNDOC_LIBRARY"] || File.join(dyndoc_home,"library") repo_dir = File.join(lib_dir,".repository") old_pwd = Dir.pwd cmd = ARGV.empty? ? :help : ARGV[0].to_sym case cmd when :help, :"--help", :"-h" doc=</ dpm install https://github.com// (equivalent to previous one) dpm install // (non necessarily on github) Good to know: repository identifier is in any previous case / Update a repository =================== # dpm update / Link library ============ dpm link /// (default link to ) dpm link /// dpm link Unlink library ============== dpm unlink This message ============ dpm help List of repository ================== dpm repo List of libraries ================= dpm ls ENDHELP puts doc when :install #default is github from now! location,url=ARGV[1],'https://github.com' if (tmp=location.split("/")).length==5 and tmp[1].empty? url=tmp[0...3].join("/") location=tmp[3..-1].join("/") end owner,package=File.split(location) package = package[0...-4] if package =~ /\.git$/ package_dir = File.join(repo_dir,owner) FileUtils.mkdir_p package_dir FileUtils.cd package_dir `git clone #{url}/#{owner}/#{package}.git` when :update FileUtils.cd File.join(repo_dir,ARGV[1]) `git pull` when :link path = File.expand_path(ARGV[1]) unless (local = (File.directory? path) ) path = ARGV[1] # not expanded end path,package = File.split(path) target = ARGV[2] || package target = File.join(lib_dir,target) FileUtils.rm target if File.symlink? target #unlink first source = local ? path : File.join(repo_dir,path,package) if RUBY_PLATFORM =~ /(?:msys|mingw)/ FileUtils.cp_r source,target else FileUtils.ln_sf source,target end when :unlink package = ARGV[1] if RUBY_PLATFORM =~ /(?:msys|mingw)/ FileUtils.rm_rf File.join(lib_dir,package) else FileUtils.rm File.join(lib_dir,package) end when :ls FileUtils.cd lib_dir Dir["*"].each_with_index{|e,i| puts "#{i+1}) #{e}"} when :repo FileUtils.cd repo_dir Dir[File.join("*","*")].each_with_index{|e,i| puts "#{i+1}) #{e}"} end FileUtils.cd old_pwd