ycl

Artifact [047beae955]
Login

Artifact [047beae955]

Artifact 047beae955496caf0b40244bb1a7de08379774cb:


#! /bin/env tclsh

namespace eval doc {}

variable doc::main {
	description {
		the main program
	}
	args {
		cmd {
			description {
				name of command to run
			}
		}
		cleanup {
			description {
				should temporary files be cleaned up?
			}
			validate {
				[string is boolean $cleanup]
			}
			default {
				set cleanup y
			}
		}
	}
	stop {
		[info exists cmd]
	}
}

proc main {args} {
	variable DBG_ERROR
	variable outsuffix
	variable tmpfiles
	variable pyim
	set argsres [checkargs doc::main args]
	set args [lrange $args[unset args] [dict get $argsres next] end]

	set res [$pyim $cmd {*}$args]
	if {$cleanup && [dict exists $res tmpfiles]} {
		foreach file [dict get $res tmpfiles] {
			puts stderr "removing $file"
			file delete -force $file
		}
	}
}

proc main_parse {} {
    uplevel {
        lappend cmdargs {*}$unknown
    }
}


#todo: check what the "canonical" way of doing this is
if {[info level] == 0} {
    set mypath [info script]
    set myname [file tail $mypath]
    set mydir [file dirname $mypath]
	set updir  [file dirname $mydir]

	set auto_path [linsert $auto_path 0 [file dirname $updir]]
	set auto_path [linsert $auto_path 0 $updir]
	package require {ycl pyim}
	variable pyim [yclprefix]::pyim
	package require {ycl proc}
	namespace import [yclprefix]::proc::checkargs
	package require {ycl verbose}
	namespace import [yclprefix]::verbose::verbose
	namespace upvar [yclprefix]::verbose DBG_INFO DBG_INFO
	namespace upvar [yclprefix]::verbose DBG_ERROR DBG_ERROR

    set res [catch {dict info $argv} eres eopts]
    if {$res} {
        dict set eopts -errorinfo "syntax error in user arguments: $argv [dict get $eopts -errorinfo]"
        return -options $eopts
    }
    main {*}$argv
}