sourceafFandocViewer::Main.fan

using flux::Main

// afFandocViewer Announced at http://fantom.org/sidewalk/topic/2116

** 
** Launch [Flux]`fandoc://flux` from the command line, using the first argument as either a uri or 
** a Windows file path. 
** 
** pre>
**   > fan afFandocViewer fandoc://sys
**   > fan afFandocViewer C:\Projects\FandocViewer\pod.fandoc
** <pre
** 
class Main {

    static Void main(Str[] args) {
        if (!args.isEmpty) {
            args = args.rw
            args[0] = toUriStr(args[0])
        }
        
        flux::Main.main(args)
    }
    
    ** *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) {
        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
    }
}