Пример #1
0
func init() {
	nflag.Configure(nflag.ConfigOptions{
		ProgramDescription: "This program will enable the bootstrapping of existing or new projects.",
	})

	nflag.Set("bootstrap", nflag.Flag{
		Descriptor:   "Bootstrap a new project.",
		Type:         "string",
		AllowNothing: false,
		Required:     false,
	})

	nflag.Set("get-dependencies", nflag.Flag{
		Descriptor:   "Get the dependencies of an existing project.",
		Type:         "bool",
		DefaultValue: false,
		AllowNothing: true,
	})

	nflag.Set("get-type-dependencies", nflag.Flag{
		Descriptor:   "Get the dependencies of a particular type (for example, typescript).",
		Type:         "string",
		AllowNothing: false,
		Required:     false,
	})

	nflag.Set("install-dependencies", nflag.Flag{
		Descriptor:   "Install the dependencies of an existing project.",
		Type:         "bool",
		DefaultValue: false,
		AllowNothing: true,
	})
}
Пример #2
0
// Init the compiler
func init() {
	nflag.Configure(nflag.ConfigOptions{ProgramDescription: "Unified compiler for specialized project components."})
	nflag.Set("compile", nflag.Flag{Type: "string", DefaultValue: "all", Required: false, AllowNothing: true})
	currentDirectory, _ = os.Getwd() // Get the current working directory from os and assign it to currentDirectory

	executableNotInstalled = " is not installed on this system."
	dirDoesNotExistInSrc = " is not a directory inside src/."
}
Пример #3
0
// Initialization
func init() {
	nflag.Configure(nflag.ConfigOptions{ShowHelpIfNoArgs: true, ProgramDescription: "Frala CLI tool for file parsing and Po conversion."})

	nflag.Set("convert-terms", nflag.Flag{ // Create the convert-terms flag
		Type:         "bool",
		Descriptor:   "Use convert-terms to declare the action of Terms to Po conversion. Don't pass for Po to Terms conversion.",
		AllowNothing: true,
	})

	nflag.Set("lang", nflag.Flag{ // Create the lang Flag
		Descriptor:   "Language to parse files, Terms to Po conversion, or Po to Terms conversion.",
		Type:         "string",
		DefaultValue: frala.Config.DefaultLanguage, // Set DefaultValue to whatever is already set in frala
		AllowNothing: true,                         // Allow nothing, since we'll just default to DefaultValue
	})

	nflag.Set("parse", nflag.Flag{ // Create the parse flag
		Descriptor: "Files to parse. Accepts comma-separated values.",
		Type:       "string",
	})

	nflag.Set("po", nflag.Flag{ // Create the po flag
		Descriptor: "Po file you wish to convert to Terms or save Terms to.",
		Type:       "string",
	})

	currentWorkingDirectory, getWdErr := os.Getwd()

	if getWdErr != nil { // If there was an error getting the working directory
		absolutePathToDir, absolutePathErr := filepath.Abs(".") // Attempt to get the absolute path of the directory

		if absolutePathErr == nil { // If there was no issue getting the absolute path of the directory
			currentWorkingDirectory = absolutePathToDir // Change currentWorkingDirectory to absolutePathToDir
		} else { // If there was an issue getting the the current working directory
			fmt.Println("Unable to determine the current working directory. Exiting.")
			os.Exit(1)
		}
	}

	nflag.Set("target-dir", nflag.Flag{ // Create the target-dir flag
		Descriptor:   "Target directory to save parsed files or Po content to.",
		DefaultValue: currentWorkingDirectory, // Current working directory
		Type:         "string",
	})
}
Пример #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)
	}
}