/// <summary>Entry point</summary> public static int Main(string[] args) { using (new ConsoleOutput()) { try { if (File.Exists(ComposerFile.NAME)) { return(new CommandLine(args, new ComposerFile(ComposerFile.NAME)).Execute()); } else { return(new CommandLine(args).Execute()); } } catch (CannotExecute e) { new Output(Console.Error).Origin(e.Origin ?? Paths.Binary()).Error(e.Message, e.Advice); return(2); } catch (EntryPointNotFoundException e) { new Output(Console.Error).Origin(Paths.Binary()).Error("Problem executing runtime", e.Message); return(2); } } }
/// <summary>Entry point</summary> public virtual int Execute(CommandLine cmd, ConfigSource configuration) { Initialize(cmd, configuration); var binary = Paths.Binary(); var proc = new Process(); var runtime = configuration.GetRuntime(); var ini = new Dictionary <string, IEnumerable <string> >() { { "magic_quotes_gpc", new string[] { "0" } }, { "date.timezone", new string[] { TimeZoneInfo.Local.Olson() ?? Environment.GetEnvironmentVariable("TZ") ?? "UTC" } }, { "extension", configuration.GetExtensions(runtime) } }; var use = configuration.GetUse() ?? UseComposer(); Encoding encoding; Func <string, string> args; var main = Paths.TryLocate(use, new string[] { Paths.Compose("tools", MainFor(cmd) + ".php") }).FirstOrDefault(); if (null == main) { main = Paths.Locate(new string[] { Paths.DirName(binary) }, new string[] { MainFor(cmd) + "-main.php" }).First(); // Arguments are encoded in utf-7, which is binary-safe args = Arguments.Encode; encoding = Encoding.UTF8; } else { args = Arguments.Escape; encoding = Encoding.GetEncoding("iso-8859-1"); } var shell = Shell.Parse(configuration.GetExecutable(runtime) ?? (runtime ?? "php")); var dot = new string[] { "." }; proc.StartInfo.UseShellExecute = false; proc.StartInfo.FileName = shell.Executable; proc.StartInfo.Arguments = string.Format( "{1} -C -q -d include_path=\"{2}{0}{0}{3}\" {4} {5} {6}", Paths.Separator, string.Join(" ", shell.Arguments), string.Join(Paths.Separator, dot.Concat(use.Concat(cmd.Path["modules"].Concat(ModulesFor(cmd))))), string.Join(Paths.Separator, dot.Concat(cmd.Path["classpath"].Concat(ClassPathFor(cmd)))), string.Join(" ", IniSettings(ini.Concat(configuration.GetArgs(runtime)))), main, string.Join(" ", ArgumentsFor(cmd).Select(args)) ); var env = proc.StartInfo.EnvironmentVariables; env["XP_EXE"] = binary; env["XP_VERSION"] = Assembly.GetExecutingAssembly().GetName().Version.ToString(); env["XP_MODEL"] = cmd.ExecutionModel.Name; env["XP_COMMAND"] = GetType().Name.ToLower(); return(cmd.ExecutionModel.Execute(proc, encoding)); }
/// <summary>Retrieve configuration via xp.ini</summary> private static ConfigSource TheConfiguration() { var home = Environment.GetEnvironmentVariable("HOME"); return(new CompositeConfigSource( new EnvironmentConfigSource(), new IniConfigSource(new Ini(Paths.Compose(".", ini))), null != home ? new IniConfigSource(new Ini(Paths.Compose(home, ".xp", ini))) : null, new IniConfigSource(new Ini(Paths.Compose(Environment.SpecialFolder.LocalApplicationData, "Xp", ini))), new IniConfigSource(new Ini(Paths.Compose(Paths.Binary().DirName(), ini))) )); }
/// <summary>Entry point</summary> public int Execute(CommandLine cmd, ConfigSource configuration) { Initialize(cmd, configuration); var proc = new Process(); var runtime = configuration.GetRuntime(); var ini = new Dictionary <string, IEnumerable <string> >() { { "magic_quotes_gpc", new string[] { "0" } }, { "date.timezone", new string[] { TimeZoneInfo.Local.Olson() ?? "UTC" } }, { "extension", configuration.GetExtensions(runtime) } }; var use = configuration.GetUse() ?? UseComposer(); Encoding encoding; Func <string, string> args; var main = Paths.TryLocate(use, new string[] { Paths.Compose("tools", MainFor(cmd) + ".php") }).FirstOrDefault(); if (null == main) { main = Paths.Locate(new string[] { Paths.Binary().DirName() }, new string[] { MainFor(cmd) + "-main.php" }).First(); encoding = Encoding.UTF8; // Arguments are encoded in utf-7, which is binary-safe args = Arguments.Encode; } else { args = Arguments.Escape; encoding = Encoding.GetEncoding("iso-8859-1"); } proc.StartInfo.UseShellExecute = false; proc.StartInfo.FileName = configuration.GetExecutable(runtime) ?? "php"; proc.StartInfo.Arguments = string.Format( "-C -q -d include_path=\".{0}{1}{0}{0}.{0}{2}\" {3} {4} {5}", Paths.Separator, string.Join(Paths.Separator, use.Concat(cmd.Options["modules"].Concat(ModulesFor(cmd)))), string.Join(Paths.Separator, cmd.Options["classpath"].Concat(ClassPathFor(cmd))), string.Join(" ", IniSettings(ini.Concat(configuration.GetArgs(runtime)))), main, string.Join(" ", ArgumentsFor(cmd).Select(args)) ); return(cmd.ExecutionModel.Execute(proc, encoding)); }
/// <summary>Entry point</summary> public override int Execute(CommandLine cmd, ConfigSource configuration) { var assembly = Assembly.GetExecutingAssembly(); var output = new Output(Console.Out) .Origin(Paths.Binary()) .Header("XP Subcommands") .Section("Builtin @ " + assembly.GetName().Version, new Output() .Line() .Each(BuiltinsIn(assembly), (self, type) => self.Line("$ xp " + type.Name.ToLower())) ) ; if (File.Exists(ComposerFile.NAME)) { using (var composer = new ComposerFile(ComposerFile.NAME)) { if (composer.Definitions.Scripts.Count > 0) { output.Section("Defined via scripts in @ " + composer.SourceUri, new Output() .Line() .Each(composer.Definitions.Scripts, (self, script) => self.Line("$ xp " + script.Key)) ); } } } foreach (var dir in cmd.Path["modules"]) { AppendCommands(output, "Module", Paths.Resolve(dir)); } AppendCommands(output, "Local", Directory.GetCurrentDirectory()); foreach (var dir in ComposerLocations()) { AppendCommands(output, "Installed", Paths.Compose(dir, "vendor")); } return(0); }
public void binary() { Assert.NotEqual("", Paths.Binary()); }