💡 What is the Idea
The idea here is to give users possibility to save any kind of option with defined value (key/value pairs) in a local json file. Then when any command will be executed, from the place where this file is located, CLI will first check all options defined in this file and if any may be used to fill the currently executed command. The local file created with the context structure could be the same json we use for apps .m365rc.json.
For example:
- user creates some context (commands not specified yet) and adds two options to it with values, as a result we have a local file created in directory
C:\Test with contents
.m365rc.json:
{
'webUrl' : 'https://contoso.sharepoint.com/sites/test',
'listTitle' : 'TestItem'
}
-
then the user runs a command C:\Test> m365 spo listitem get --id 147. The user did not define the webUrl option which is a required one and listId nor listTitle to specify the list so the command should fail. But CLI will first check if any of the options defined in the .m365rc.json may be used to prefill any option in this command and if yes CLI will use them. So as a result the command will work just fine 😊
-
the user steps out of the location C:\Test and runs the command again C:\> m365 spo listitem get --id 147. As a result the command will fail as the user did not specify needed options and there was no local context JSON file CLI could use
-
the user goes back to C:\Test and runs the command C:\Test> m365 spo listitem get --id 147 --listTitle 'Different'. Now the command will also work and webUrl will be taken from the context but the listTitle won't as it was already defined by the user
-
the user runs the command m365 spo list get. The command will fail. Although the webUrl option will be used which is required one, but the listTitle will not be used as the command needs title option to get the specified list.
💪 What to do ?
In order to achieve this we would need this kind of commands:
Originally Discussed in 👉 #2853
💡 What is the Idea
The idea here is to give users possibility to save any kind of option with defined value (key/value pairs) in a local json file. Then when any command will be executed, from the place where this file is located, CLI will first check all options defined in this file and if any may be used to fill the currently executed command. The local file created with the context structure could be the same json we use for apps
.m365rc.json.For example:
C:\Testwith contents.m365rc.json:
then the user runs a command
C:\Test> m365 spo listitem get --id 147. The user did not define thewebUrloption which is a required one andlistIdnorlistTitleto specify the list so the command should fail. But CLI will first check if any of the options defined in the.m365rc.jsonmay be used to prefill any option in this command and if yes CLI will use them. So as a result the command will work just fine 😊the user steps out of the location
C:\Testand runs the command againC:\> m365 spo listitem get --id 147. As a result the command will fail as the user did not specify needed options and there was no local context JSON file CLI could usethe user goes back to
C:\Testand runs the commandC:\Test> m365 spo listitem get --id 147 --listTitle 'Different'. Now the command will also work andwebUrlwill be taken from the context but thelistTitlewon't as it was already defined by the userthe user runs the command
m365 spo list get. The command will fail. Although thewebUrloption will be used which is required one, but thelistTitlewill not be used as the command needstitleoption to get the specified list.💪 What to do ?
In order to achieve this we would need this kind of commands:
m365 context init- New command: m365 context init 🧺 #4042m365 context remove- New command: m365 context remove 🧺 #4043m365 context option list- New command: m365 context option list 🧺 #4044m365 context option add [options]- New command: m365 context option set 🧺 #4045m365 context option remove [options]- New command: m365 context option remove 🧺 #4046Originally Discussed in 👉 #2853