How to pass boolean argument to delve in VS Code? - debugging

I am trying to pass argument to delve through VS Code but it doesn't work.
This is how to pass argument to a go program through delve:
dlv debug github.com/docker/swarm -- create
I tried many different solution in my launch.json:
"args": [
"--",
"create"
]
"args": [
"--create"
]
"args": [
"create"
]

After many attempts, I found the right one:
"args": [
"--create",
"true"
]

Related

Save terminal tabs to saved workspace VSCode

Is it possible to save Terminal settings to a workspace? For most of my projects I always have two terminal tabs open. One where I do all of my git work and one where I run gulp tasks. These are two different folders and neither are the project root. When I open a saved workspace it always just opens one tab to the project root.
Look at the Restore Terminals extension. For example, in your settings.json:
"restoreTerminals.runOnStartup": false, // true is the default
// set to false if using a keybinding or command palette
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "git",
"commands": [
"cd <your directory>",
"npm run test" // your git command(s)
]
}
]
},
{
"splitTerminals": [
{
"name": "gulp",
"commands": [
"cd zip",
"gulp sass"
]
}
]
}
]
will open two terminals, one for your git work and one for the gulp work. They can each take multiple commands.
Example keybinding:
{
"key": "shift+alt+t", // whatever keybinding if you wish
"command": "restore-terminals.restoreTerminals",
},
or you can it run at start-up.
The Tasks feature is the current recommended way to handle this. There is no need for an extension. See Automating launching of terminals in the VS Code documentation.
Then make sure that tasks are run automatically when the folder is opened by running command Tasks: Manage Automatic Tasks in Folder and choosing Allow Automatic Tasks in Folder (see Run behavior).
Please also see the note here that:
Task support is only available when working on a workspace folder. It is not available when editing single files."
For a Linux not-so-officially-recommended way that works. The xdotool key emulator for linux can be used. I'm sure any Windows key emulator could be used to accomplish the same thing.
First, set the Terminal: Change Color to a keyboard shortcut. Here I'm using Ctrl+Shift+C. This is done by bringing up the command pallet (Cntrl+Shift+P) and, typing Terminal: Change Color
Here is my Restore Terminals json from VS Code settings. The lengthy cli command to update the colors needs to be activated on the last tab, as it is the tab that is focused when Restore Tabs is finished restoring tabs.
We need a bit of a timeout between the setting of each tab color, as VS Code takes just about a 10th of a second to complete the command. The built in keyboard shortcut cntrl+Page_Up is used to bring the previous tabs into focus. This script is for a WorkSpace that includes a Docker-Compose enviroment that contains 3 repos.
Be sure to save this in your Workspace settings, not your user settings. For more info, visit: https://code.visualstudio.com/docs/getstarted/settings
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "docker-compose",
"commands": ["cd ..", "cd docker-compose", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "api",
"commands": ["cd ..", "cd api", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "ui",
"commands": [
"cd ..",
"cd ui",
"xdotool key ctrl+shift+c && xdotool type 'cyan' && xdotool key Return && sleep .2",
"xdotool key ctrl+Page_Up && xdotool key ctrl+shift+c && xdotool type 'green' && xdotool key Return && sleep .2",
"xdotool key ctrl+Page_Up && xdotool key ctrl+shift+c && xdotool type 'yellow' && xdotool key Return",
"clear"
]
},
]
}
],
And the end result... Is that all tab colors are updated after they are restored.
Of course, anyone who has ever used keyboard emulation for automating tasks should know you can not be entering text or clicking elsewhere until the task is complete.
If you're on windows you can use powershell to create a similar effect to #CodeBloodedChris's solution.
Create a powershell script in your workspace root directory (or where ever the last terminal's final path is) and name it something like 'restore-terminal-customization.ps1' or something like that. Then add the following code to it:
# Uses windows forms to send keystrokes to customize vscode Terminals
Add-Type -AssemblyName System.Windows.Forms
$tabDelay = .6
# Last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^+cRed~")
# Second to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cYellow~")
# Third to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cMagenta~")
In this script the '^+c' is ctrl+shift+c and '~' is the enter key.
Similarly I had also set up a keybinding for the icons which uses ctrl+shift+i '^+i'. Here's an example of setting both the color and the icon of a terminal:
# Fourth to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cGreen~^+iorganization~")
In your restoreTerminal's config call the script you created as a command in the last terminal on your list.
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "docker-compose",
"commands": ["cd ..", "cd docker-compose", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "api",
"commands": ["cd ..", "cd api", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "ui",
"commands": [
"cd ..",
"cd ui",
".\restore-terminal-customization.ps1",
"clear"
]
},
]
}
],
Don't forget to set the keybindings to the Terminal: Change Color and Terminal: Change Icon commands in VsCode.

Jelastic - how to get the environment variables to a Docker container

How do I get the environment placeholders to show up inside a Docker container?
The documentation doesn't seem to be exactly clear where those can be used. I have tried to just set those inside the node env as shown in a JPS file that is added to this question.
For example, it shows the environment as env-2461411 and its name as Environment Test in the environment options
Once the environment is launched, the placeholders are still as they show in the JPS file, and not replaced by the actual values.
Result
Placeholders don't seem to be replaced, and as such the shell doesn't like the environment it gets:
-bash: ${env.appid}: bad substitution
-bash: ${env.displayName}: bad substitution
-bash: ${env.domain}: bad substitution
-bash: ${env.envName}: bad substitution
-bash: ${env.name}: bad substitution
-bash: ${env.shortdomain}: bad substitution
-bash: ${env.url}: bad substitution
-bash: ${env.appid}: bad substitution
-bash: ${env.displayName}: bad substitution
-bash: ${env.domain}: bad substitution
-bash: ${env.envName}: bad substitution
-bash: ${env.name}: bad substitution
-bash: ${env.shortdomain}: bad substitution
-bash: ${env.url}: bad substitution
Expected result
Environment variables showing in the bash environment, such as
env_domain=env-2461411
env_name=Environment Test
Example JPS file
{
"jpsType": "install",
"jpsVersion": "1.4",
"name": "Environment Test",
"description":
{
"text": "Template for testing environment variables test",
"short": "Environment variables test"
},
"logo": "https://raw.githubusercontent.com/jelastic-jps/start-stop-scheduler/master/images/logo.png",
"homepage": "https://jelastic.com/",
"categories":
[
"apps/testing"
],
"success":
{
"text": "## Environment test is up and running\nOpen the Jelastic SSH gateway and locate the test-node, see its environment with `env`"
},
"nodes":
[
{
"image": "debian",
"extip": false,
"count": 1,
"cloudlets": 16,
"fixedCloudlets": 1,
"nodeType": "docker",
"nodeGroup": "test",
"displayName": "test-node",
"volumes":
[
"/root"
],
"env":
{
"env_appid": "${env.appid}",
"env_domain": "${env.domain}",
"env_url": "${env.url}",
"env_displayname": "${env.displayName}",
"env_envname": "${env.envName}",
"env_name": "${env.name}",
"env_shortdomain": "${env.shortdomain}"
}
}
],
"onInstall":
{
"log": "${placeholders}"
}
}
During the process of environment's creation mentioned placeholders are not initialized and can't be used.
You can use the method AddContainerEnvVars.
In your case, it will be like this.

Filter logstash does not work with Grok Debugger

I use Grok Debugger to verify my pattern which is: %{DATA:evolution} %{DATA:value}
But the problem that it does not read the content of the variable "value".
If I want to use two successive strings, how can I do that please?
Use WORD instead of DATA which captures also spaces:
%{WORD:evolution} %{WORD:value}
Results:
{
"evolution": [
[
"Send"
]
],
"value": [
[
"functionHandle"
]
]
}

Sublime build system to open file at local server address

For a website I'm developing with the help of a local server (running at http://127.0.0.1:4000), I try to write a build system for my Sublime Text project settings.
I have access to these variables (provided by Sublime Text):
$file: Stores the absolute path to the file on disk:C:\Users\User\dev\repos\base\dir\index.html
$project_path: Stores the location of the project file (usually the root of the project):C:\Users\User\dev\repos\base
Now what I want is the content of $file but instead of the $project_path I want http://127.0.0.1:4000/~base. For that task I tried the following with Bash cmd.exe:
CALL SET result=%file:%project_path%=http://127.0.0.1:4000\~base\% && echo %result%
This gives the desired result, however I can't seem to be able to apply it to the build system inside Sublime Text.
For now, I try to generate the correct address and output it via cmd.exe:
{
"build_systems":
[
{
"name": "Preview in browser",
"selector": "text.html",
"windows":
{
"shell": true,
"cmd": [
"start", "cmd", "/k",
"CALL SET result=$file:$project_path=http://127.0.0.1:4000\\~base\\ && echo $result"
]
}
}
]
}
Result:
> echo %result%
C:\Users\Philipp\dev\repos\base\dir\index.html:C:\Users\Philipp\dev\repos
\base=http://127.0.0.1:4000\~base\
So the substitution is not working when doing it in the build system, but in cmd.exe it does. I'm confused.
You can do something like this:
{
"build_systems":
[
{
"name": "Preview in browser",
"selector": "text.html",
"windows":
{
"shell_cmd": "CALL SET filePath=$file && CALL SET result=%filePath:$project_path=http://127.0.0.1:4000\\~base% && CALL C:/Progra~2/Google/Chrome/Application/chrome.exe %result%"
}
}
]
}
The problem was with windows replacement and variable asignation rather than with sublime builds.
As it has been said in chat and comments multiple CALL are necessary to use the real value variable because if not used windows will expand their value at parse time before the wanted value is asigned at execution time. In addition, shell_cmd can be used to run a unique command in shell.

Error in custom sublime build for knitr markdown

I'm trying to create my own sublime-build in Sublime Text 3, since the default build in knitr package (https://sublime.wbond.net/packages/knitr) doesn't work (for me). I modified the one in knitr package as follows:
{
"selector": "text.html.markdown.knitr",
"working_dir": "${project_path:${folder}}",
"cmd": ["Rscript", "-e", "library(knitr); knit('$file')" ],
"shell": true
}
but get the error:
Error: '\G' is an unrecognized escape in character string starting "'C:\G"
Execution halted
[Finished in 0.4s with exit code 1]
[cmd: ['Rscript', '-e', "library(knitr); knit('C:\\GitHub\\Projects\\test\\testLaTeXing\\knitrRmd\\testRmd.Rmd')"]]
obviously some windows path escape issue, but how can I fix this, when I want to acces file path dynamically?
I'm working on windows7.
Try setting your "cmd" line to this:
"cmd": ["Rscript", "-e", "library(knitr); knit('${file/\\\\/\//}')" ],
Basically, it's a regular expression to match two \ characters and replace them with one / character. Each \ and / needs to be escaped by a \, hence the chicken scratch.
I'm not on Windows to test, but theoretically this should work. If it doesn't, another option to try is
"cmd": ["Rscript", "-e", "library(knitr); knit('${file/\\\\/\\/}')" ],
where it's replacing the \\ with a single \.
Please let me know how it works, I'm interested to know!
This is what I finally cooked up, thanks to #MattDMo.
{
"selector": "text.html.markdown.knitr",
"working_dir": "${project_path:${folder}}",
"cmd": [ "Rscript -e \"library(knitr); knit('$file', output='$file_path/$file_base_name.md')\"" ],
"shell": true,
"windows":
{
"selector": "text.html.markdown.knitr",
// "working_dir": "${project_path:${folder}}",
// "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"cmd": ["Rscript", "-e", "library(knitr); knit('${file/\\\\/\\/\/g}', output='${file_path/\\\\/\\/\/g}/$file_base_name.md' )" ],
"shell": true
}
}
where the default command is from the knitr sublime package (https://github.com/andrewheiss/SublimeKnitr/blob/master/knitr-Markdown.sublime-build)

Resources