Posts

Showing posts from July, 2022

Migrate SQLPrompt Snippets to VSCode

 I love snippets; love em. And I have a whole bunch in RedGate SQL Prompt. Now I want to be able to use those in VSCode as well, but boy do I dread having to retype all of them. Solution? Python! First arg is the path where your SQLPrompt snippets are Second arg is the directory where you want it to spit out a "sql.json" file with all your snippets. """ A script to translate sqlprompt snippet files to vscode formatted snippets """ import os import json import glob import io import argparse class SQLPromptPlaceholder :     """Represents the values of a SQLPrompt placeholder"""     def __init__ ( self , name , default_value ):         self . name = name         self . default_value = default_value class SQLPromptSnippet :     """Represents the content of a SQLPrompt snippet"""     @ staticmethod     def from_file ( filename ):         """Generates an instance fr

Boolean Command Line Options with CommandLineParser lib

So I like the CommandLineParser library for C# command line applications. One thing that tripped me up however was the handling of boolean inputs. Most people are aware of "flags" in shell scripting. For example, in bash, "-a" is an argument for the command "ls". "-a" is conceptually a boolean flag whose presence informs the application "do not ignore entries starting with .". This is in comparison to a parameter with a value, as in "-Path" in "Get-ChildItem -Path C:\" where "C:\" is the value of the parameter "-Path". Flags   are always true if present and assumed to be false if absent . In the CommandLineParser library, you can do Flag-like parameters with the bool  datatype. You can also give them a default value of either true or false (using the DefaultValue argument on the Option attribute). The problem is, if you make the default value true, you might as well not even add it as a parameter