示例#1
0
func main() {
	nflag.Parse() // Parse nflag

	OriginalLanguage = frala.Config.DefaultLanguage                     // Set OriginalLanguage before doing any parsing or conversion
	frala.Config.DefaultLanguage, _ = nflag.GetAsString("lang")         // Change DefaultLanguage to whatever may be set as lang. This may not change if no value is passed to lang
	frala.Config.Direction = frala.GetDirection(frala.Config.Direction) // Ensure we have an accurate Direction

	parseFiles, parseFilesErr := nflag.GetAsString("parse")
	poFile, poFileErr := nflag.GetAsString("po")

	TargetDirectory, _ = nflag.GetAsString("target-dir")
	TargetDirectory += "/" // Ensure / is appending to end of path

	if (parseFilesErr == nil) && (parseFiles != "") { // If we are parsing files
		ParseFiles(parseFiles) // Call ParseFiles
	} else if (poFileErr == nil) && (poFile != "") { // If we are doing Po conversion
		convertTermsVal, convertTermsGetErr := nflag.GetAsBool("convert-terms") // Get the boolean value of convert-terms

		if convertTermsGetErr != nil { // If there was an error getting convertTermsVal
			convertTermsVal = false // Don't convert from Terms to Po
		}

		PoConversion(convertTermsVal, poFile) // Do Po conversion
	} else { // If we are neither parsing nor doing Po conversion
		nflag.PrintFlags() // Print the nflag flags
	}
}
示例#2
0
// Main executing function
func main() {
	nflag.Parse() // Parse flags

	var initializationSuccess bool                                        // Define initializationSuccess as a bool, defaults to false
	var initializationErrorMessage string                                 // Define initializationErrorMessage as a string
	configContent, configFetchErr := ioutil.ReadFile("build/config.json") // Read build/config if it exists

	if configFetchErr == nil { // If there was no error
		decodeError := json.Unmarshal(configContent, &projectConfig) // Decode the JSON configContent into projectConfig (config struct)

		if decodeError == nil { // If there was no decodeError
			initializationSuccess = true // Define initializationSuccess as true
		} else { // If there was a decodeError
			initializationErrorMessage = "Failed to decode the configuration file."
		}
	} else { // If the was an error reading the configuration
		initializationErrorMessage = "No config file found in the build folder of this project."
	}

	if initializationSuccess { // If initialization was successful
		lowercaseProjectName = strings.ToLower(projectConfig.Name) // Lowercase the Project Name and set to lowercaseProjectName
		var selectiveContentTypes []string                         // Define selectiveContentTypes as the array of types of content we will be compiling
		providedContentTypes, _ := nflag.GetAsString("compile")    // Get the nflag value for compile, if any

		if providedContentTypes == "all" {
			selectiveContentTypes = projectConfig.ContentTypes // Define selectiveCompileTypes as all the compile types define in the project config
		} else { // If all is not defined
			selectiveContentTypes = strings.Split(providedContentTypes, ",") // Separate by comma the providedContentTypes, allowing multiple or one to be specified
		}

		fmt.Println("Compiling " + projectConfig.Name)

		for _, contentType := range selectiveContentTypes { // For each compile type
			var compileError error
			fmt.Println("Compiling " + strings.Title(contentType) + ".")

			switch strings.ToLower(contentType) {
			case "go":
				compileError = CompileGo() // Compile Go
			case "html":
				compileError = CompileHTML() // Compile HTML
			case "less":
				compileError = CompileLESS() // Compile Less
			case "typescript":
				compileError = CompileTypeScript() // Compile TypeScript
			default:
				compileError = errors.New(contentType + " is not a valid type.")
			}

			if compileError != nil { // If there was a compile error
				fmt.Println(compileError) // Print the error
			}
		}

		fmt.Println("Finished compiling " + projectConfig.Name)
	} else { // If initialization was not successful
		fmt.Println(initializationErrorMessage)
	}
}
示例#3
0
func main() {
	nflag.Parse()                                                        // Parse nflag
	projectBootstrap, _ := nflag.GetAsString("bootstrap")                // Get any bootstrap string passed
	getDependencies, _ := nflag.GetAsBool("get-dependencies")            // Should we get dependencies of an existing project
	getTypeDependencies, _ := nflag.GetAsString("get-type-dependencies") // Get dependencies of a particular type
	installDependencies, _ := nflag.GetAsBool("install-dependencies")    // Should we install dependencies of an existing project

	if projectBootstrap != "" { // If we are bootstrapping a new project
		BootstrapProject(projectBootstrap) // Call BootstrapProject with the project name
	} else if getDependencies || installDependencies { // If we are getting or installing the dependencies of an existing project
		projectConfigContent, projectConfigReadError := ioutil.ReadFile("build/config.json") // Read the build/config.json file if it exists

		if projectConfigReadError == nil { // If there was no read error
			var projectConfig codeutilsShared.ProjectConfig                     // Define projectConfig as a ProjectConfig
			decodeError := json.Unmarshal(projectConfigContent, &projectConfig) // Decode / unmarshal projectConfigContent as &ProjectConfig

			if decodeError == nil { // If there was no decode error
				if getDependencies { // If we are getting the dependencies of a project
					PrintDependencies(projectConfig) // Print the dependencies of the project
				} else { // If we are installing the dependencies of a project
					InstallProjectDependencies(projectConfig) // Attempt installation of the project's dependencies
				}
			} else { // If there was a decode error
				fmt.Println("There was an error decoding the config.json file.")
			}
		} else { // If there is no config.json file
			fmt.Println("No config.json file exists in the build folder.")
		}
	} else if getTypeDependencies != "" { // If we are getting dependencies from a specific type
		dependencyMap, dependencyExists := DependenciesMap[getTypeDependencies] // Get the dependencyMap of the getTypeDependencies if it exists in DependenciesMap

		if dependencyExists { // If the dependencyExists
			fmt.Println("Dependencies: ", strings.Join(dependencyMap.Dependencies, ", "))
			fmt.Println("Packager: " + dependencyMap.Packager)
		} else { // If this type does not exist
			fmt.Println("Type \"" + getTypeDependencies + "\" is not a valid dependency type.")
		}
	} else {
		nflag.PrintFlags() // Print nflag flags
	}
}
示例#4
0
func main() {
	// #region Load or Create new config

	metisCliFolderExists := metis.IsDir(root, true) // Use IsDir from metis to check if .metis-cli folder exists

	if metisCliFolderExists { // If the .metis-cli folder exists
		ReadConfig() // Read the config
	} else {
		saveFailure := SaveConfig() // Save the config

		if saveFailure != nil { // If there was a save failure
			fmt.Println(saveFailure)
		}
	}

	if config.Clusters == nil { // If Clusters is a nil map
		config.Clusters = make(map[string]string) // Create a map and assign it to Clusters
	}

	// #endregion

	// #region Setup Flags and Variables

	// Set a configure flag that accepts a string of what we are going to
	nflag.Set("configure", nflag.Flag{Descriptor: "Configure this command line utility.", Type: "string"})

	// Set a node flag that accepts a string of a Node Group or Node name
	// Used in conjunction with get and set
	nflag.Set("node", nflag.Flag{Descriptor: "Specify the name of the " + NodeGroupOrNode + " you are getting or setting a property of.", Type: "string"})

	// Set a get flag that accepts a string, we check if it is "all" or a Node Group / node key
	nflag.Set("get", nflag.Flag{
		Descriptor: "Fetch local CLI option / all or a specific " + NodeGroupOrNode,
		Type:       "string",
	})

	// Set a cache flag that accepts nothing. So long as it is provided, it is considered true
	nflag.Set("cache", nflag.Flag{Descriptor: "Cache the NodeList from the Cluster", Type: "bool", AllowNothing: true})

	// Set a push flag that accepts nothing. So long as it is provided, it is considered true
	nflag.Set("push", nflag.Flag{Descriptor: "Push the local NodeList to the Cluster", Type: "bool", AllowNothing: true})

	// Set an add-ng flag that accepts a string for a Node Group name
	nflag.Set("add-ng", nflag.Flag{Descriptor: "Add a Node Group", Type: "string"})

	// Set an add flag that accepts a string for a Node name
	nflag.Set("add", nflag.Flag{Descriptor: "Add a Node", Type: "string"})

	// Set a set flag that accepts a string of a Node Group or Node name to update
	nflag.Set("set", nflag.Flag{Descriptor: "Set a property of a " + NodeGroupOrNode, Type: "string"})

	// Set a delete flag that accepts a string of a Node Group or Node name to delete
	nflag.Set("delete", nflag.Flag{Descriptor: "Delete a " + NodeGroupOrNode, Type: "string"})

	nflag.Parse() // Parse the flags

	nodeCommand, _ := nflag.GetAsString("node")
	configureCommand, _ := nflag.GetAsString("configure")
	getCommand, _ := nflag.GetAsString("get")

	cacheCommand, _ := nflag.GetAsBool("cache")
	pushCommand, _ := nflag.GetAsBool("push")

	addNgCommand, _ := nflag.GetAsString("add-ng")
	addCommand, _ := nflag.GetAsString("add")
	setCommand, _ := nflag.GetAsString("set")
	deleteCommand, _ := nflag.GetAsString("delete")

	// #endregion

	var commandError error

	if config.ActiveCluster != "" { // If there is an active cluster
		ReadNodeList() // Read the nodeList and initialize Metis (if possible)

		if configureCommand != "" { // If we are configuring an aspect of our local CLI
			commandError = Configure(configureCommand) // Call Configure and set any error to commandError
		} else if getCommand != "" { // If we are getting a config option or information about a Node Group or Node
			if getCommand == "status" { // If we are getting the status of the Cluster
				commandError = Status("get")
			} else { // If we are not getting the status of the Cluster
				commandError = Get(nodeCommand, getCommand) // Get all properties or a specific property for the Node Group or Node
			}
		} else if cacheCommand { // If we are caching the NodeList from the Cluster
			commandError = Cache() // Call cache and set any error to commandError
		} else if pushCommand { // If we are pushing the local NodeList from the Cluster
			commandError = Push() // Call push and set any error to commandError
		} else if addNgCommand != "" { // If we are adding a Node Group
			commandError = Add(addNgCommand, "group")
		} else if addCommand != "" { // If we are adding a Node
			commandError = Add(addCommand, "node")
		} else if setCommand != "" { // If we are setting the status of the Cluster OR a property of a Node Group or Node
			if setCommand == "status" { // If we are setting the status of the Cluster
				commandError = Status("set")
			} else { // If we are setting the property of a Node Group or Node
				commandError = Set(nodeCommand, setCommand) // Set the property of this Node Group or Node
			}
		} else if deleteCommand != "" { // If we are deleting a Node Group or Node
			commandError = Delete(deleteCommand)
		}
	} else { // If there was an error reading the NodeList
		if (configureCommand == "active-cluster") || (configureCommand == "cluster") { // If the configure command is defined as active-cluster or cluster
			commandError = Configure(configureCommand) // Call Configure with the command
		} else { // If neither configure nor set were provided
			commandError = errors.New("No Active Cluster defined. Use" + nflag.Config.FlagString + "configure=active-cluster and/or " + nflag.Config.FlagString + "configure=cluster to create a Cluster.")
		}
	}

	if commandError != nil { // If there was an error during our command
		fmt.Println(commandError)
	}
}