Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions cmd/manifest/diff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2022-2026 Salesforce, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package manifest

import (
"github.com/opentracing/opentracing-go"
"github.com/slackapi/slack-cli/internal/app"
"github.com/slackapi/slack-cli/internal/cmdutil"
"github.com/slackapi/slack-cli/internal/manifest"
"github.com/slackapi/slack-cli/internal/prompts"
"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/style"
"github.com/spf13/cobra"
)

// NewDiffCommand implements the "manifest diff" command, which prints the
// differences between the project manifest and the app settings on Slack.
func NewDiffCommand(clients *shared.ClientFactory) *cobra.Command {
return &cobra.Command{
Use: "diff",
Short: "Show differences between the project manifest and app settings",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I feel we should say App Settings Slack API, but the CLI currently references App Settings, so I thought I'd stay consistent.

Long: "Compare the project manifest with app settings and print any differences.",
Example: style.ExampleCommandsf([]style.ExampleCommand{
{Command: "manifest diff", Meaning: "Show differences between project manifest and app settings"},
{Command: "manifest diff --app A0123456789 --token xoxp-...", Meaning: "Show manifest differences without prompts"},
}),
Args: cobra.NoArgs,
PreRunE: func(cmd *cobra.Command, args []string) error {
return cmdutil.IsValidProjectDirectory(clients)
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
span, ctx := opentracing.StartSpanFromContext(ctx, "cmd.manifest.diff")
defer span.Finish()

selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly)
if err != nil {
return err
}

clients.Config.ManifestEnv = app.SetManifestEnvTeamVars(clients.Config.ManifestEnv, selection.App.TeamDomain, selection.App.IsDev)

localManifest, err := clients.AppClient().Manifest.GetManifestLocal(ctx, clients.SDKConfig, clients.HookExecutor)
if err != nil {
return err
}

remoteManifest, err := clients.AppClient().Manifest.GetManifestRemote(ctx, selection.Auth.Token, selection.App.AppID)
if err != nil {
return err
}

diffs, err := manifest.Diff(localManifest.AppManifest, remoteManifest.AppManifest)
if err != nil {
return err
}

if !diffs.HasDifferences() {
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "books",
Text: "App Manifest",
Secondary: []string{"Project manifest and app settings match"},
}))
return nil

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: We don't return a non-zero exit code when there is a manifest diff. Ideally, we should. However, manifest validate does not return a non-zero exist code on when the manifest is invalid and the CLI plumbing would surface a visual error to interactive users. So, we should have a follow-up task to standardize non-zero exit code handling.

}

manifest.DisplayDiffs(ctx, clients.IO, diffs)
return nil
},
}
}
90 changes: 90 additions & 0 deletions cmd/manifest/diff_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2022-2026 Salesforce, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package manifest

import (
"context"
"testing"

"github.com/slackapi/slack-cli/internal/app"
"github.com/slackapi/slack-cli/internal/hooks"
"github.com/slackapi/slack-cli/internal/prompts"
"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/shared/types"
"github.com/slackapi/slack-cli/test/testutil"
"github.com/spf13/cobra"
"github.com/stretchr/testify/mock"
)

func TestDiffCommand(t *testing.T) {
testutil.TableTestCommand(t, testutil.CommandTests{
"prints match message when manifests match": {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
appSelectMock := prompts.NewAppSelectMock()
appSelectPromptFunc = appSelectMock.AppSelectPrompt
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(
prompts.SelectedApp{
App: types.App{AppID: "A001"},
Auth: types.SlackAuth{Token: "xapp"},
}, nil)
manifestMock := &app.ManifestMockObject{}
manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{
AppManifest: types.AppManifest{
DisplayInformation: types.DisplayInformation{Name: "App"},
},
}, nil)
manifestMock.On("GetManifestRemote", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{
AppManifest: types.AppManifest{
DisplayInformation: types.DisplayInformation{Name: "App"},
},
}, nil)
cf.AppClient().Manifest = manifestMock
cf.SDKConfig = hooks.NewSDKConfigMock()
},
ExpectedOutputs: []string{"match"},
},
"prints differences when project and app settings disagree": {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
appSelectMock := prompts.NewAppSelectMock()
appSelectPromptFunc = appSelectMock.AppSelectPrompt
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(
prompts.SelectedApp{
App: types.App{AppID: "A002"},
Auth: types.SlackAuth{Token: "xapp"},
}, nil)
manifestMock := &app.ManifestMockObject{}
manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{
AppManifest: types.AppManifest{
DisplayInformation: types.DisplayInformation{Name: "Project Name"},
},
}, nil)
manifestMock.On("GetManifestRemote", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{
AppManifest: types.AppManifest{
DisplayInformation: types.DisplayInformation{Name: "Remote Name"},
},
}, nil)
cf.AppClient().Manifest = manifestMock
cf.SDKConfig = hooks.NewSDKConfigMock()
},
ExpectedOutputs: []string{
"display_information.name",
"Project Name",
"Remote Name",
},
},
}, func(clients *shared.ClientFactory) *cobra.Command {
return NewDiffCommand(clients)
})
}
1 change: 1 addition & 0 deletions cmd/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
}

// Add child commands
cmd.AddCommand(NewDiffCommand(clients))
cmd.AddCommand(NewInfoCommand(clients))
cmd.AddCommand(NewValidateCommand(clients))

Expand Down
Loading
Loading