Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>Returns the given module and a unique list of dependencies of a given module</summary>
        private IEnumerable <string> DependenciesAndSelf(string dir, string module, HashSet <string> loaded)
        {
            var path = Paths.Compose(dir, module.Replace('/', Path.DirectorySeparatorChar));

            yield return(path);

            loaded.Add(module);

            using (var composer = new ComposerFile(Paths.Compose(path, ComposerFile.NAME)))
            {
                foreach (var require in composer.Definitions.Require.Where(pair => pair.Key.Contains('/')))
                {
                    if (loaded.Contains(require.Key))
                    {
                        continue;
                    }

                    foreach (var transitive in DependenciesAndSelf(dir, require.Key, loaded))
                    {
                        yield return(transitive);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>Returns the given module and a unique list of dependencies of a given module</summary>
        private IEnumerable<string> DependenciesAndSelf(string dir, string module, HashSet<string> loaded)
        {
            var path = Paths.Compose(dir, module.Replace('/', Path.DirectorySeparatorChar));
            yield return path;
            loaded.Add(module);

            using (var composer = new ComposerFile(Paths.Compose(path, ComposerFile.NAME)))
            {
                foreach (var require in composer.Definitions.Require.Where(pair => pair.Key.Contains('/')))
                {
                    if (loaded.Contains(require.Key)) continue;

                    foreach (var transitive in DependenciesAndSelf(dir, require.Key, loaded))
                    {
                        yield return transitive;
                    }
                }
            }
        }