Documentation
¶
Overview ¶
Package dtproject is the Projects module of the DataTug terminal UI: the list of local and GitHub projects, the screens of an open project, the wizard that creates a project and the flow that adds DataTug to an existing GitHub repository.
Every screen is an Elm-style nav.Screen. Work that touches the disk, the network or the keyring is a tea.Cmd returning a result message, and anything that outlives one message (a clone, the GitHub device flow) is a stream: a command that starts the work and a command per progress message. Package variables in seams.go are the only doors to the outside world, so tests replace them instead of starting real processes.
Index ¶
- Constants
- Variables
- func CreateLocalProject(projectID, title, location string) (dtconfig.ProjectRef, error)
- func DemoModule() datatugui.Module
- func IsCloudRef(ref dtconfig.ProjectRef) bool
- func Module() datatugui.Module
- func NewGitHubDeviceAuth(opts GitHubAuthOptions) nav.Screen
- func OpenCloudProject(p cloudproject.Project, page []string) tea.Cmd
- func OpenDeepLink(link deeplink.Link) tea.Cmd
- type GitHubAuthOptions
Constants ¶
const ( // PersonalCloudNotice is the line for a personal (no Space) cloud project. PersonalCloudNotice = "Personal DataTug Cloud projects can't be opened in the terminal yet. Move the project to a Space to open it here." // ReadOnlyHint is shown for any edit of a cloud project. ReadOnlyHint = "Edit this project on datatug.app" )
Notices of DataTug Cloud projects.
const DefaultGitHubClientID = githubClientID
DefaultGitHubClientID is the client ID of the DataTug OAuth app, used with GitHub's device flow: https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow
Variables ¶
var CloudErrorLine = func(err error) string { return err.Error() }
CloudErrorLine is the one-line message for a failed cloud read. The commands package sets it so the UI and the exit lines word errors the same way.
var CloudLoader func(ctx context.Context, ref cloudproject.Ref) (cloudproject.Project, error)
CloudLoader reads a cloud project with the saved login. The commands package sets it; it is nil when the UI runs without one (tests).
Functions ¶
func CreateLocalProject ¶ added in v0.59.0
func CreateLocalProject(projectID, title, location string) (dtconfig.ProjectRef, error)
CreateLocalProject is the writer of the "Locally" tab of the create screen: it writes a new project under location and registers it, and returns the registered project. It is exported so that the commands of the CLI can be tested against the project the wizard makes (the two must agree on where a project is).
func DemoModule ¶ added in v0.159.0
DemoModule shows registered projects without the standard GitHub flows.
func IsCloudRef ¶ added in v0.141.0
func IsCloudRef(ref dtconfig.ProjectRef) bool
IsCloudRef reports whether a settings entry is a DataTug Cloud project.
func NewGitHubDeviceAuth ¶ added in v0.159.0
func NewGitHubDeviceAuth(opts GitHubAuthOptions) nav.Screen
NewGitHubDeviceAuth returns a nav.Screen that runs GitHub's OAuth device flow with the given options.
func OpenCloudProject ¶ added in v0.141.0
func OpenCloudProject(p cloudproject.Project, page []string) tea.Cmd
OpenCloudProject returns the command that shows an already loaded cloud project at the section of page and records it as a recent project.
Types ¶
type GitHubAuthOptions ¶ added in v0.159.0
type GitHubAuthOptions struct {
// ClientID overrides DefaultGitHubClientID when non-empty.
ClientID string
// Scope requests a specific OAuth scope when non-empty (default "repo").
Scope string
// Explanation is shown above the device code instructions when non-empty.
Explanation string
// NoSecret disables reading GITHUB_OAUTH_SECRET from the environment.
NoSecret bool
// OnDone, when non-nil, produces the message emitted when the flow finishes
// (success or error) instead of the default Pop + githubAuthenticated / ReportError.
OnDone func(token *oauth2.Token, err error) tea.Msg
// OnCancel, when non-nil, produces the message emitted when the user cancels
// instead of the default nav.Pop().
OnCancel func() tea.Msg
// Optional overrides for testing; nil uses the package's ghauth functions.
RequestDeviceCode func(ctx context.Context, clientID, scope string) (*ghauth.DeviceCodeResponse, error)
PollForToken func(ctx context.Context, clientID, clientSecret, deviceCode string, interval int, onAttempt func(int)) (*oauth2.Token, error)
SaveToken func(token *oauth2.Token) error
}
GitHubAuthOptions configures a reusable GitHub device-flow screen.