# Getting Started

## Log in to your WorkflowGen server

Before using the WorkflowGen CLI to interact with your WorkflowGen server, you need to log in to it. See the [`login`](https://docs.workflowgen.com/cli/1.0.0/list-of-commands#login) section for more information.

```
wfg login http://YOUR_SERVER/wfgen -u wfgen_admin -p YourPassword -c DEV
```

## Managing a project

A project is composed of processes, sub-processes, custom workflow applications, global lists, and webform assets.

A project is based on a manifest file definition (see the [Project Manifest](https://docs.workflowgen.com/cli/1.0.0/project-manifest) section).

Managing a project with the CLI allows you to export or import the content easily.

### Create a simple project

In most cases, a WorkflowGen project is composed of processes and sub-processes. The following manifest defines a project with one process and two sub-processes, with one global list:

```json
{
  "version": "1.0",
  "tag": "1.1.0",
	"processes":[
    {
      "name":"EMPLOYEE_ONBOARDING",
      "version":1,
      "folder":"HR"
    }
  ],
  "subProcesses":[
    {
      "name":"CREATE_AD_ACCOUNT",
      "version":1,
      "folder":"IT"
    },
    {
      "name":"CREATE_ERP_ACCESS",
      "version":1,
      "folder":"IT"
    }
  ],
  "globalLists": [
    "Country"
  ]
}
```

You can use the [`project init`](https://docs.workflowgen.com/cli/1.0.0/list-of-commands#init) command to build the manifest with the CLI, or write the definition directly in a `manifest.json` file.

{% hint style="info" %}
If you add webform assets to your manifest, be sure that you have correctly set the path to the webform folder on the WorkflowGen server.

The webform path is also required if you want to export process code (contained in the `Default.aspx` file).
{% endhint %}

#### Export your project

Once your `manifest.json` file is correctly defined, you can use the [`project export`](https://docs.workflowgen.com/cli/1.0.0/list-of-commands#export) command to download all sources' links to your project.

```
wfg project export -p PathToTheFolderWithTheManifest
```

For the manifest definition, you should have a folder structure like the following:

```
| manifest.json
| definitions/
|    globallists/
|        Country.Xml
|    subprocesses/
|        CREATE_AD_ACCOUNTv1.xml
|        CREATE_ERP_ACCESSv1.xml
|    processes/
|        EMPLOYEE_ONBOARDINGv1.xml
| src/
|    processes/
|        CREATE_AD_ACCOUNT/
|                V1/
|                    Default.aspx
|                    Default.aspx.cs
|        CREATE_ERP_ACCESS/
|                V1/
|                    Default.aspx
|                    Default.aspx.cs
|        EMPLOYEE_ONBOARDING/
|                V1/
|                    Default.aspx
|                    Default.aspx.cs
```

#### Import your project

With the [`project import`](https://docs.workflowgen.com/cli/1.0.0/list-of-commands#import) command you can import your project into another WorkflowGen server (such as the production server).

```
wfg project import --source PathToYourProjectFolder
```

The CLI will import all definitions into your WorkflowGen application, and will create processes, sub-processes, applications, and global lists, and move webform assets to the webform folder.

### Video example

{% embed url="<https://www.loom.com/share/8c64acc59c4f4b96abfc678312453bbc>" %}

## Using a multiple server configuration

The CLI uses contexts to identify which server and user to use to connect to WorkflowGen. You can define more than one configuration, one for each of your WorkflowGen servers.

The `login` command contains the `--context` option to give a name to your context.

With the `config get-contexts` command you can display all contexts defined.

```
wfg config get-contexts
```

**Result:**

```
 ----------------------------------------------------- 
 | Current | Context name | Server name | User name  |
 ----------------------------------------------------- 
 |         | PROD         | CG9FDCK57K  | ZQPWB00VS3 |
 ----------------------------------------------------- 
 | *       | DEV          | CB6YHR11DD  | ACJTLYG0AZ |
 ----------------------------------------------------- 
 
 Count: 2
```

You can switch to another context with the `config use-context` command.

```
wfg config use-context PROD
```

## Global options

The CLI provides some global options to give you some other information.

### `help`

With the `help` option, you can get information on how to use a specific command or see which commands are available.

```
wfg --help
```

**Result:**

```
Usage:
  wfg [options] [command]

Options:
  --debug
  --verbose
  --version         Show version information
  -?, -h, --help    Show help and usage information

Commands:
  login <url>
  config
  process
  project
  global-list
  application
  graphql <query>
```

### `debug`

With the `debug` option, you can display more logs in your terminal during the command execution.

```
wfg process get --debug
```

### `verbose`

The `verbose` option is like the `debug` option, but the CLI will display more logs than it does for `debug`.

```
wfg process get --verbose
```

### `version`

The `version` option returns your current WorkflowGen CLI version.

```
wfg --version
```

## Enabling tab completion

{% tabs %}
{% tab title="PowerShell" %}

1. Install the `dotnet-suggest` global tool:

   ```
   dotnet tool install --global dotnet-suggest
   ```
2. Open your PowerShell profile and add the following code to it. You can get the path to your profile path with `echo $PROFILE`.

   ```bash
   # dotnet suggest shell start
   $availableToComplete = (dotnet-suggest list) | Out-String
   $availableToCompleteArray = $availableToComplete.Split([Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries) 


       Register-ArgumentCompleter -Native -CommandName $availableToCompleteArray -ScriptBlock {
           param($commandName, $wordToComplete, $cursorPosition)
           $fullpath = (Get-Command $wordToComplete.CommandElements[0]).Source

           $arguments = $wordToComplete.Extent.ToString().Replace('"', '\"')
           dotnet-suggest get -e $fullpath --position $cursorPosition -- "$arguments" | ForEach-Object {
               [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
           }
       }
   $env:DOTNET_SUGGEST_SCRIPT_VERSION = "1.0.0"
   # dotnet suggest script end
   ```

{% endtab %}

{% tab title="Bash" %}

1. Install the `dotnet-suggest` global tool:

   ```bash
   dotnet tool install --global dotnet-suggest
   ```
2. Open your bash profile (`~/.bash_profile`) and add the following code to it:

   ```bash
   # dotnet suggest shell complete script start
   _dotnet_bash_complete()
   {
       local fullpath=`type -p ${COMP_WORDS[0]}`
       local escaped_comp_line=$(echo "$COMP_LINE" | sed s/\"/'\\\"'/g)
       local completions=`dotnet-suggest get --executable "${fullpath}" --position ${COMP_POINT} -- "${escaped_comp_line}"`

       if [ "${#COMP_WORDS[@]}" != "2" ]; then
           return
       fi

       local IFS=$'\n'
       local suggestions=($(compgen -W "$completions"))

       if [ "${#suggestions[@]}" == "1" ]; then
           local number="${suggestions[0]/%\ */}"
           COMPREPLY=("$number")
       else
           for i in "${!suggestions[@]}"; do
               suggestions[$i]="$(printf '%*s' "-$COLUMNS"  "${suggestions[$i]}")"
           done

           COMPREPLY=("${suggestions[@]}")
       fi
   }

   _dotnet_bash_register_complete()
   {
       local IFS=$'\n'
       complete -F _dotnet_bash_complete `dotnet-suggest list`
   }
   _dotnet_bash_register_complete
   export DOTNET_SUGGEST_SCRIPT_VERSION="1.0.1"
   # dotnet suggest shell complete script end
   ```

{% hint style="info" %}
To use the `dotnet-suggest` tools, you need to install .NET Core 3.1.
{% endhint %}
{% endtab %}
{% endtabs %}
