One Liners - Useful ObjectScript Commands One Line Long
Folks!
Recently I found several one-line long ObjectScript commands on DC and think that it'd be great not to lose it and to collect more!
So I decided to gather a few first cases, put in one OEX project, and share them with you!

And here is how you can use them.
1. Create client SSL configuration.
set $namespace="%SYS", name="DefaultSSL" do:'##class(Security.SSLConfigs).Exists(name) ##class(Security.SSLConfigs).Create(name)Useful if you need to read content from an URL.
Don't forget to return to a previous namespace. Or add
n $namespacebefore the call. Once you go up in the stack the namespace will be switched to your current namespace automatically.
2. Install ZPM
set $namespace="%SYS" do ##class(Security.SSLConfigs).Create("ssl") set r=##class(%Net.HttpRequest).%New(),r.Server="pm.community.intersystems.com",r.SSLConfiguration="ssl" do r.Get("/packages/zpm/latest/installer"),$system.OBJ.LoadStream(r.HttpResponse.Data,"c")Useful, if you don't have ZPM in your IRIS and can install with this one call in the terminal.
Courtesy of @Guillaume Rongier and @Sergei Shutov and @Sergey Mikhailenko
3. Create %All Namespace:
set $namespace="%SYS",P("Globals")="%DEFAULTDB",sc=##class(Config.Namespaces).Create("%All",.P)Courtesy of @Eduard Lebedyuk and @Alexey Maslov
4. Enable IRIS BI in a current namespace:
do EnableDeepSee^%SYS.cspServer("/csp/"_$$$LOWER($namespace))Courtesy of @Benjamin De Boe
Please add your useful lines :) Collaboration is very welcome!
Comments
Great idea, thanks Eugene! But I think it is necessary to collect not so much beautiful one-line useful constructions, but more useful pieces of code, as it was in the projects: https://github.com/intersystems-community/code-snippetshttps://github.com/intersystems-community/objectscript-snippetshttps://github.com/eduard93/Utils
Snippets are great and deserve attention, but one-liners have a very certain use case, when you can execute it from the command line or as a docker image tweak
Propose No. 5 Create a new database and namespace with resources and mapping in interoperability and install a module from the register into it, for example "dc-one-liners"
At the end of line No. 2 of the zpm installation:
set $namespace="%SYS" do ##class(Security.SSLConfigs).Create("ssl") set r=##class(%Net.HttpRequest).%New(),r.Server="pm.community.intersystems.com",r.SSLConfiguration="ssl" do r.Get("/packages/zpm/latest/installer"),$system.OBJ.LoadStream(r.HttpResponse.Data,"c") zpm "install zapm" zapm "newdb dc-one-liners"
And you can create any number of such one-liners for all possible cases ;-)
Or add
n $namespacebefore the call. Once you go up in the stack the namespace will be switched to your current namespace automatically.
It would not unless you exit the current stack level. To achieve it, you should perform the one-liner as an argument of Xecute command, making it less pleasant, e.g.
x "new $namespace set $namespace=""%SYS"",P(""Globals"")=""%DEFAULTDB"",sc=##class(Config.Namespaces).Create(""%All"",.P)"you should perform the one-liner as an argument of Xecute command
Bonus: you can New other variables if you want, e.g.
x "new $namespace,P set $namespace=""%SYS"",P(""Globals"")=""%DEFAULTDB"",sc=##class(Config.Namespaces).Create(""%All"",.P)"This is really cool, @Alexey Maslov ! Updated two one-liners with your suggestion!
Released a new version with @Alexey Maslov suggestion and two new one-liners, courtesy of @Sylvain Guilbaud
This is great, thank you Evgeny!! Here is another one that I use, often from the Output window in Studio in order to execute an OS-level command (I most frequently use this for p4 commands to interact with my Perforce server from my IRIS server). IIRC, original credit goes to @Timothy Leavitt
Kill stream Set sc = ##class(%Studio.SourceControl.ISC).RunCmd("<insert OS Command here>",.stream,,1) w ! do stream.OutputToDevice() If 'sc { Write $System.Status.GetErrorText(sc) }Thanks @Ben Spead ! How is this different from:
USER>!<cmd line>@Evgeny Shvarov - you cannot use "!<cmd line>" from the Output window of Studio. It is often very helpful to run a command from the context of a serverside Caché/InterSystems IRIS process which you can do via the Output Window with the above command, but not with "!":
!whoamiwhoami - Error <SYNTAX>Kill stream Set sc = ##class(%Studio.SourceControl.ISC).RunCmd("whoami",.stream,,1) w ! do stream.OutputToDevice() If 'sc { Write $System.Status.GetErrorText(sc) }CMD: whoamiirisusrAgain, this is particularly useful when running server-side source control commands (if you need to debug or augment hooks)
A typical use case is WebTerminal !
Good point Robert!
I'm not sure ) This is a command line, yes?
just checked:.png)
Thanks for the additional use-case :)
and that's the effective code behind
Set rc=$zf(-1,cmd_" 2> """_errorfile_""" > """_outputfile_"""")
Hey, here's another one-liner: Change password for preset users
x "new $namespace,s,p,n set $namespace=""%SYS"",p(""Password"")=""NewPass123"" for n=""admin"",""cspsystem"",""iam"",""superuser"",""unknownuser"",""_system"",""_ensemble"" set s=##class(Security.Users).Modify(n,.p)"
@Sergey Mikhailenko - this is great! Could you please send a PR?
"reset" terminal session
%SYS 4d3>kill zremove quit %SYS>
This would only kill variables at the current stack level. I think you rather want to do:
%SYS 4d3>quit %SYS>kill zremove
Nevertheless a useful tip. Many people don't seem to realize that they need to issue a quit to unwind the stack after an error.
Good point, I guess it depends on the variables scope at that stack level, I generally just run it twice.
Either way, as you say, it is useful to know to do this to ensure "leftovers" don't interfere with later commands.
Another one-liner suggested by @Robert Cemper recently:
k^SPOOLs%io=$I O 2 u 2ZW%anyvariable c 2 u %ioE.g. if you want to expose the content of %request during REST API method debugging, to write all the contents of %request to ^SPOOL global:
k^SPOOLs%io=$I O 2 u 2ZW%request c 2 u %ioand then ZW ^SPOOL in the terminal.