Refactor getItem
This commit is contained in:
parent
07a8d13d1e
commit
ca429e9bf8
@ -2,7 +2,7 @@
|
|||||||
// existing M365 account. Data displayed is representative of the current
|
// existing M365 account. Data displayed is representative of the current
|
||||||
// serialization abstraction versioning used by Microsoft Graph and stored by Corso.
|
// serialization abstraction versioning used by Microsoft Graph and stored by Corso.
|
||||||
|
|
||||||
package main
|
package exchange
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -24,52 +24,36 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/data"
|
"github.com/alcionai/corso/src/internal/data"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
"github.com/alcionai/corso/src/pkg/credentials"
|
"github.com/alcionai/corso/src/pkg/credentials"
|
||||||
"github.com/alcionai/corso/src/pkg/logger"
|
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getCmd = &cobra.Command{
|
|
||||||
Use: "get",
|
|
||||||
Short: "Get a M365ID item JSON",
|
|
||||||
RunE: handleGetCommand,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Required inputs from user for command execution
|
// Required inputs from user for command execution
|
||||||
var (
|
var (
|
||||||
tenant, user, m365ID, category string
|
user, tenant, m365ID, category string
|
||||||
)
|
)
|
||||||
|
|
||||||
// main function will produce the JSON String for a given m365 object of a
|
func AddCommands(parent *cobra.Command, userFlag, tenantFlag string) {
|
||||||
// user. Displayed Objects can be used as inputs for Mockable data
|
user = userFlag
|
||||||
// Supports:
|
tenant = tenantFlag
|
||||||
// - exchange (contacts, email, and events)
|
|
||||||
// Input: go run ./getItem.go --user <user>
|
|
||||||
//
|
|
||||||
// --m365ID <m365ID> --category <oneof: contacts, email, events>
|
|
||||||
func main() {
|
|
||||||
ctx, _ := logger.SeedLevel(context.Background(), logger.Development)
|
|
||||||
ctx = SetRootCmd(ctx, getCmd)
|
|
||||||
|
|
||||||
defer logger.Flush(ctx)
|
exCmd := &cobra.Command{
|
||||||
|
Use: "exchange",
|
||||||
|
Short: "Get a M365ID item JSON",
|
||||||
|
RunE: handleExchangeCmd,
|
||||||
|
}
|
||||||
|
|
||||||
fs := getCmd.PersistentFlags()
|
fs := exCmd.PersistentFlags()
|
||||||
fs.StringVar(&user, "user", "", "m365 user id of M365 user")
|
|
||||||
fs.StringVar(&tenant, "tenant", "",
|
|
||||||
"m365 Tenant: m365 identifier for the tenant, not required if active in OS Environment")
|
|
||||||
fs.StringVar(&m365ID, "m365ID", "", "m365 identifier for object to be created")
|
fs.StringVar(&m365ID, "m365ID", "", "m365 identifier for object to be created")
|
||||||
fs.StringVar(&category, "category", "", "type of M365 data (contacts, email, events or files)") // files not supported
|
fs.StringVar(&category, "category", "", "type of M365 data (contacts, email, events or files)") // files not supported
|
||||||
|
|
||||||
cobra.CheckErr(getCmd.MarkPersistentFlagRequired("user"))
|
cobra.CheckErr(exCmd.MarkPersistentFlagRequired("user"))
|
||||||
cobra.CheckErr(getCmd.MarkPersistentFlagRequired("m365ID"))
|
cobra.CheckErr(exCmd.MarkPersistentFlagRequired("m365ID"))
|
||||||
cobra.CheckErr(getCmd.MarkPersistentFlagRequired("category"))
|
cobra.CheckErr(exCmd.MarkPersistentFlagRequired("category"))
|
||||||
|
|
||||||
if err := getCmd.ExecuteContext(ctx); err != nil {
|
parent.AddCommand(exCmd)
|
||||||
logger.Flush(ctx)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleGetCommand(cmd *cobra.Command, args []string) error {
|
func handleExchangeCmd(cmd *cobra.Command, args []string) error {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
|
|
||||||
if utils.HasNoFlagsAndShownHelp(cmd) {
|
if utils.HasNoFlagsAndShownHelp(cmd) {
|
||||||
37
src/cmd/getM365/main.go
Normal file
37
src/cmd/getM365/main.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
. "github.com/alcionai/corso/src/cli/print"
|
||||||
|
"github.com/alcionai/corso/src/cmd/getM365/exchange"
|
||||||
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
var user, tenant string
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "getM365",
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ctx, _ := logger.SeedLevel(context.Background(), logger.Development)
|
||||||
|
|
||||||
|
ctx = SetRootCmd(ctx, rootCmd)
|
||||||
|
defer logger.Flush(ctx)
|
||||||
|
|
||||||
|
rootCmd.PersistentFlags().StringVar(&user, "user", "", "m365 user id of M365 user")
|
||||||
|
rootCmd.PersistentFlags().StringVar(&tenant, "tenant", "",
|
||||||
|
"m365 Tenant: m365 identifier for the tenant, not required if active in OS Environment")
|
||||||
|
|
||||||
|
exchange.AddCommands(rootCmd, user, tenant)
|
||||||
|
|
||||||
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -122,7 +122,7 @@ func readTestConfig() (map[string]string, error) {
|
|||||||
TestCfgSecondaryUserID,
|
TestCfgSecondaryUserID,
|
||||||
os.Getenv(EnvCorsoSecondaryM365TestUserID),
|
os.Getenv(EnvCorsoSecondaryM365TestUserID),
|
||||||
vpr.GetString(TestCfgSecondaryUserID),
|
vpr.GetString(TestCfgSecondaryUserID),
|
||||||
"lidiah@8qzvrj.onmicrosoft.com",
|
"adelev@8qzvrj.onmicrosoft.com",
|
||||||
//"lynner@8qzvrj.onmicrosoft.com",
|
//"lynner@8qzvrj.onmicrosoft.com",
|
||||||
)
|
)
|
||||||
fallbackTo(
|
fallbackTo(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user