- Pods
- Fandoc Viewer 1.0.10
- API
- Main
- Src
sourceafFandocViewer::Main.fan
using flux::Main
using util
// afFandocViewer Announced at http://fantom.org/sidewalk/topic/2116
** Launch [Flux]`http://fantom.org/doc/flux/#overview` from the command line, passing in
** a pod name, a uri, or a Windows file path.
**
** pre>
** C:\> fan afFandocViewer fandoc://sys
** C:\> fan afFandocViewer C:\Projects\FandocViewer\pod.fandoc
** <pre
class Main : AbstractMain {
@Arg { help="pod name, file or url. e.g. afFandocViewer, pod.fandoc, http://www.fantomfactory.org/" }
Str? file
@Opt { help="Install Fandoc Viewer Flux Tools" }
Bool install
@Opt { help="Print version"; aliases=["v"] }
Bool version
override Int main(Str[] args := Env.cur.args) {
argsOk := parseArgs(args)
if (version)
echo(Pod.of(this).name + "-" + Pod.of(this).version)
if (install)
return InstallScript().main
if (helpOpt || file == null)
return usage
flux::Main.main([toUriStr(file)])
return 0
}
override Int run() { -1 }
** *Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.*
**
** > Jamie Zawinski (1997)
**
** See `http://regex.info/blog/2006-09-15/247`
internal static Str toUriStr(Str str) {
typeUri := toType(str)
if (typeUri != null) return typeUri
if (str.startsWith("af")) {
afStr := "af" + str[2..-1].capitalize
typeUri = toType(afStr)
if (typeUri != null) return typeUri
}
// check if str is too small to have a scheme
if (str.size <= 3)
return str
if (str.chars[0].isAlpha && str.chars[1] == ':' && str.chars[2] == '\\')
str = str.replace("\\", "/")
if (str.chars[0].isAlpha && str.chars[1] == ':' && str.chars[2] == '/')
str = "file:///$str"
return str
}
private static Str? toType(Str str) {
if (str == "/" || str == "//")
return "fandoc://"
if (Pod.find(str, false) != null)
return "fandoc://${str}"
if (str.split('/').size == 2) {
podName := str.split('/')[0]
typeName := str.split('/')[1]
qname := "${podName}::${typeName}"
if (Type.find(qname, false) != null)
return "fandoc://${podName}/${typeName}"
qname = "${podName}::${typeName.capitalize}"
if (Type.find(qname, false) != null)
return "fandoc://${podName}/${typeName.capitalize}"
}
if (str.split(':').size == 3) {
podName := str.split(':')[0]
typeName := str.split(':')[2]
qname := "${podName}::${typeName}"
if (Type.find(qname, false) != null)
return "fandoc://${podName}/${typeName}"
qname = "${podName}::${typeName.capitalize}"
if (Type.find(qname, false) != null)
return "fandoc://${podName}/${typeName.capitalize}"
}
return null
}
}