コード例 #1
0
ファイル: main.go プロジェクト: nmakiya/tritium
func main() {
	if len(os.Args) > 1 {
		command := os.Args[1]

		if command == "package" {

			if len(os.Args) > 3 {
				if os.Args[2] == "--name" {
					// Build the package specified by the path
					path := os.Args[3]
					pkg := packager.NewPackage(packager.DefaultPackagePath, packager.BuildOptions())
					pkg.Load(path)
					//pkg.SerializedOutput()
					//fmt.Println(pkg.DebugInfo())

				} else if os.Args[2] == "--output-path" {
					_, path := packager.OutputDefaultPackage(os.Args[3])
					fmt.Println("Output default package to:", path)
				}

			} else {
				pkg := packager.BuildDefaultPackage()
				pkg.SerializedOutput()
			}

		} else if command == "pkginfo" {
			name := os.Args[2]
			pkg := packager.NewPackage(packager.DefaultPackagePath, packager.BuildOptions())
			pkg.Load(name)
			fmt.Println(pkg.DebugInfo())
		} else if command == "doc" {
			name := os.Args[2]
			pkg := packager.NewPackage(packager.DefaultPackagePath, packager.BuildOptions())
			pkg.Load(name)
			fmt.Println(doc.Process(pkg.Package))
		} else if command == "apollo-doc" {
			if len(os.Args) < 3 {
				fmt.Println("Usage: tritium apollo-doc <output-file>")
				os.Exit(1)
			}
			outputFile := os.Args[2]

			doc.Generate(outputFile)
		} else if command == "link" {
			fmt.Println("Linking files found in the directory:", os.Args[2])
			//LinkerToBytes(os.Args[2])
		} else if command == "test" {
			fmt.Println("Running tests found in the directory:", os.Args[2])
			if len(os.Args) == 3 {
				test.TestCustomSuite(os.Args[2])
			} else {
				fmt.Println("Usage:\n    tritium test <package_name> <optional_mixer_path>")
			}
		} else if command == "benchmark" {
			fmt.Println("Bencmarking tests found in the directory:", os.Args[2])
			if len(os.Args) == 3 {
				test.BenchmarkCustomSuite(os.Args[2])
			} else {
				fmt.Println("Usage:\n    tritium benchmark <path_to_tests_from_root>")
			}
		} else if command == "debug" {
			fmt.Println("Running tests found in the directory:", os.Args[2])
			if len(os.Args) == 3 {
				s.All(command, os.Args[2])
			} else if len(os.Args) == 4 {
				s.All(command, os.Args[2], os.Args[3])
			} else {
				fmt.Println("Usage:\n    tritium test <package_name> <optional_mixer_path>")
			}

		} else if command == "old_test" {
			fmt.Println("Running tests found in the directory:", os.Args[2])
			if len(os.Args) == 3 {
				s.All(command, os.Args[2])
			} else if len(os.Args) == 4 {
				s.All(command, os.Args[2], os.Args[3])
			} else {
				fmt.Println("Usage:\n    tritium test <package_name> <optional_mixer_path>")
			}

		} else {
			fmt.Println("No such command", command)
			show_usage()
		}
	} else {
		show_usage()
	}
}
コード例 #2
0
ファイル: doc.go プロジェクト: nmakiya/tritium
func (d *DefinitionList) generatePackageDocs(name string) {
	options := packager.BuildOptions()
	options["generate_docs"] = true
	pkg := packager.NewPackage(packager.DefaultPackagePath, options)
	pkg.Load(name)

	for tindex, ttype := range pkg.Types {
		ttypeString := null.GetString(ttype.Name)

		for _, fun := range pkg.Functions {
			stub := FuncStub(pkg.Package, fun)

			if tindex == int(null.GetInt32(fun.ScopeTypeId)) && d.Definitions[ttypeString][stub] == nil {

				function := &FunctionDefinition{
					Name:        null.GetString(fun.Name),
					ParentScope: ttypeString,
					ShortStub:   ShortFuncStub(pkg.Package, fun),
					PackageName: name,
				}
				function.setID()
				description := null.GetString(fun.Description)

				if len(description) > 0 {
					lines := make([]string, 0)

					// Trim the description. Haml doesn't like extra new lines
					for _, line := range strings.Split(description, "\n") {
						if len(strings.TrimLeft(line, " \r\n")) > 0 {
							lines = append(lines, line)
						}
					}

					//function.Description = description

					// Hacky ... I need a way to specify the indent level to play nice w haml:
					function.Description = strings.Join(lines, "\n        ")
				}

				// Description / Examples will come when we can look at comment nodes

				function.Stub = stub
				segments := strings.Split(function.Stub, ")")

				function.CallPattern = segments[0] + ")"

				function.ReturnType = fun.ReturnTypeString(pkg.Package)
				function.YieldType = fun.OpensTypeString(pkg.Package)

				//println("Getting body for function: " + stub + " from package : " + name)
				ancestralScope, ancestralStub := d.findAncestralFunction(pkg.Package, fun)

				if ancestralScope != nil {
					//println("Found ancestral function in scope:" + *ancestralScope)
					ancestralFunction := d.Definitions[*ancestralScope][*ancestralStub]

					delete(d.Definitions[*ancestralScope], *ancestralStub) // Delete it

					//println("Loading body from package:" + ancestralFunction.PackageName)
					function.Body = getBody(ancestralFunction.PackageName, fun)
				} else {
					function.Body = getBody(name, fun)
				}

				// Hacky ... I need a way to specify the indent level for the body text to play nice w haml:
				function.Body = strings.Join(strings.Split(function.Body, "\n"), "\n            ")

				if d.Definitions[ttypeString] == nil {
					d.Definitions[ttypeString] = make(map[string]*FunctionDefinition)
				}
				d.Definitions[ttypeString][stub] = function
			}
		}
	}

	return
}