> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/sast-and-sca/ocular/top-level-commands.md).

# Top-Level Commands

| Command                       | Description                          |
| ----------------------------- | ------------------------------------ |
| [help](#help)                 | Interactive help                     |
| [workspace](#workspace)       | Access to the workspace directory    |
| [importCode](#importcode)     | Create new project from code         |
| [importCpg](#importcpg)       | Create new project from existing CPG |
| [cpg](#cpg)                   | CPG of the active project            |
| [project](#project)           | Currently active project             |
| [open](#open)                 | Open project                         |
| [close](#close)               | Close project by name                |
| [delete](#delete)             | Close and remove project from disk   |
| [reloadPolicy](#reloadpolicy) | reload policy                        |
| [run](#run)                   | Run analyzer on active CPG           |
| [save](#save)                 | Write all changes to disk            |
| [undo](#undo)                 | Undo effects of analyzer             |
| [config](#config)             | The Ocular configuration object      |
| [version](#version)           | Prints the version of Ocular         |
| [banner](#banner)             | Prints the Ocular banner             |

### help <a href="#help" id="help"></a>

* Interactive help

```
ocular> help 
res33: Helper = Welcome to the interactive help system. Below you find a table of all available
top-level commands. To get more detailed help on a specific command, just type

`help.<command>`.

Try `help.importCode` to begin with.
_______________________________________________________________________________
 command     | description                         | example                  |
==============================================================================|
 close       | Close project by name               | close(projectName)       |
 cpg         | CPG of the active project           | cpg.method.l             |
 delete      | Close and remove project from disk  | delete(projectName)      |
 importCode  | Create new project from code        | importCode("example.jar")|
 importCpg   | Create new project from existing CPG| importCpg("cpg.bin.zip") |
 open        | Open project                        | open("projectName")      |
 project     | Currently active project            | project                  |
 reloadPolicy| reload policy                       | reloadPolicy             |
 run         | Run analyzer on active CPG          | run.securityprofile      |
 save        | Write all changes to disk           | save                     |
 undo        | undo effects of analyzer            | undo                     |
 workspace   | Access to the workspace directory   | workspace                |
```

![](/files/CRrxFX9wuboXxDrdB2dv)

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### workspace <a href="#workspace" id="workspace"></a>

The Workspace object - see [Organizing Projects](/sast-and-sca/ocular/organizing-projects.md)

* List available projects in workspace and see which one is open

```
ocular> workspace 
res0: io.shiftleft.console.workspacehandling.WorkspaceManager[io.shiftleft.repl.OcularProject] = 
_______________________________________________________________________________
| name    | overlays                    | inputPath                      | open|
|==============================================================================|
| x42-c   | semanticcpg,dataflow,tagging| /home/user/x42/c           | true|
| x42-java| semanticcpg,dataflow,tagging| /home/user/x42/java/X42.jar| true|
```

![](/files/CRrxFX9wuboXxDrdB2dv)

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

* Reset workspace and delete all projects and CPGs

```
// warning, highly destructive action
ocular> workspace.reset
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### importCode <a href="#importcode" id="importcode"></a>

Create code property graph from code and create a new project in the workspace for it.

* List available language frontends

```
ocular> importCode
______________________________________________________
| name      | description                  | available|
|=====================================================|
| c         | Fuzzy Parser for C/C++       | true     |
| csharp    | C# Source Frontend (Roslyn)  | false    |
| golang    | Golang Source Frontend       | false    |
| java      | Java/Dalvik Bytecode Frontend| false    |
| javascript| Javascript Source Frontend   | false    |
| llvm      | LLVM Bitcode Frontend        | false    |
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

* Import code - guessing programming language

```
ocular> importCode("/path/to/vlc-3.0.8")
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

* Import code using a specific language frontend

```
ocular> importCode.c("/path/to/vlc-3.0.8")
ocular> importCode.java("/path/to/a.jar")
...
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

* Import code from string

```
ocular> importCode.c.fromString("int main() { return 0; } ")
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### importCpg <a href="#importcpg" id="importcpg"></a>

* Import Code Property Graph for analysis

```
ocular> importCpg("/path/to/cpg.bin.zip")
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### cpg <a href="#cpg" id="cpg"></a>

* Cpg of the active project

```
ocular> cpg
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### project <a href="#project" id="project"></a>

* Currently active project

```
ocular> project
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### open <a href="#open" id="open"></a>

* Open project by name

```
ocular> open("project-name")
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### close <a href="#close" id="close"></a>

* Close project by name

```
ocular> close("project-name")
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### save <a href="#save" id="save"></a>

* Write all changes to disk

```
ocular> save
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### delete <a href="#delete" id="delete"></a>

* Close project and remove it from disk

```
ocular> delete("x42-java") 
res26: Option[Unit] = Some(())
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### run <a href="#run" id="run"></a>

* List available layer creators that can be run to enhance the graph. The command `run.$name` executes the layer creator named `$name`. `run($query)` runs the `$query` as a custom layer creator, e.g., `run(cpg.method.newTagNode("foo"))` applies the tag "foo" to all methods.

```
ocular> run 

________________________________________________________________________
| name           | description                                          |
|=======================================================================|
| semanticcpg    | linked code property graph                           |
| securityprofile| vulnerability analysis performed by Qwiet AI by Harness|
| dataflow       | graph enhancements required for data flow engine     |
| tagging        | applies tags based on policy                         |
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### undo <a href="#undo" id="undo"></a>

* Undo effects of analyzer

```
ocular> undo 
res2: better.files.File = /home/user/.shiftleft/ocular/workspace/x42-java/overlays/tagging

ocular> undo 
res3: better.files.File = /home/user/.shiftleft/ocular/workspace/x42-java/overlays/dataflow
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### regenerateCacheOnNextLoad <a href="#regeneratecacheonnextload" id="regeneratecacheonnextload"></a>

Applies to Ocular only

* create new policy cache on next load/import
* use e.g. if you edited the policy text files - on first usage they are being converted to an efficient binary format, which is being cached

```
ocular> regenerateCacheOnNextLoad 
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### reloadPolicy <a href="#reloadpolicy" id="reloadpolicy"></a>

Applies to Ocular only

* Reload policies

```
ocular> reloadPolicy 
Loading dynamic policies from /home/user/.shiftleft/ocular/policy/dynamic/jvm
Loading static policies from /home/user/.shiftleft/ocular/policy/static
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### config <a href="#config" id="config"></a>

* Print the Ocular installation path

```
ocular> config.install.rootPath 
res0: better.files.File = /home/user/.shiftleft/ocular
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### version <a href="#version" id="version"></a>

* Print the Ocular version

```
ocular> version 
res0: String = "0.3.114"
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

### banner <a href="#banner" id="banner"></a>

* Print the 1337 Ocular banner

```
ocular> banner 

 ██████╗  ██████╗██╗   ██╗██╗      █████╗ ██████╗
██╔═══██╗██╔════╝██║   ██║██║     ██╔══██╗██╔══██╗
██║   ██║██║     ██║   ██║██║     ███████║██████╔╝
██║   ██║██║     ██║   ██║██║     ██╔══██║██╔══██╗
╚██████╔╝╚██████╗╚██████╔╝███████╗██║  ██║██║  ██║
 ╚═════╝  ╚═════╝ ╚═════╝ ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝ 
Version: 0.3.114
Type `help` or `browse(help)` to begin
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)
