Skip to content

Commit 4b9e1b7

Browse files
Added Require Export and LTPath Configuration options (#31)
1 parent 962e2f0 commit 4b9e1b7

File tree

9 files changed

+230
-66
lines changed

9 files changed

+230
-66
lines changed

README.md

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
[![Sponsor Me!](https://img.shields.io/badge/%F0%9F%92%B8-Sponsor%20Me!-blue)](https://github.com/sponsors/nathan-fiscaletti)
44
[![Go Report Card](https://goreportcard.com/badge/github.com/letstrygo/letstry)](https://goreportcard.com/report/github.com/letstrygo/letstry)
55

6-
letstry is a powerful tool designed to provide temporary work-spaces for developers, built in Golang. It allows you to quickly create new projects, save them as templates, and export them to a more permanent location.
6+
**letstry** is a lightweight yet powerful tool designed to give developers **templated workspaces** directly within their preferred IDE. Written in Go, it lets you spin up new projects quickly, save them as templates, and export them to a permanent location**all from your VSCode terminal.**
77

88
## Index
99

1010
- [Installation](#installation)
1111
- [Usage](#usage)
12-
- [Create a new session](#creating-a-new-session)
12+
- [Configuration](#configuration)
13+
- [Create a new session or project](#creating-a-new-session-or-project)
1314
- [Export a session](#exporting-a-session)
1415
- [List active sessions](#listing-active-sessions)
1516
- [Managing Templates](#managing-templates)
16-
- [Configuration](#configuration)
1717
- [Contributing](#contributing)
1818
- [Development](#development)
1919

2020
## Installation
2121

22-
Letstry requires Go to be installed on your system. If you do not have Go installed, you can download it from the [official website](https://golang.org/dl/).
22+
**letstry** requires Go to be installed on your system. If you do not have Go installed, you can download it from the [official website](https://golang.org/dl/).
2323

2424
Once Go is installed, to install letstry, run the following command:
2525

@@ -44,15 +44,70 @@ echo "alias lt='letstry'" >> ~/.bashrc && source ~/.bashrc
4444

4545
## Usage
4646

47-
### Creating a new Session
47+
### Configuration
48+
49+
> [!TIP]\
50+
> You can retrieve the path to the config file using the `lt path config` command. By default, the configuration is stored in `~/.letstry/config.json`.
51+
52+
By default, letstry is set-up as a **temporary workspace manager**. This means calls to `lt new` will result in a temporary workspace being created in your systems temporary directory that will be deleted once it's associated editor window is closed. This behavior can be customized using the `projects_path` and `require_export` configuration fields.
53+
54+
**Windows Config Example**
55+
56+
```jsonc
57+
{
58+
// Projects Path
59+
//
60+
// The path in which to store projects. By default, letstry
61+
// will use a temporary directory.
62+
//
63+
// If no projects path is set, `require_export` will be
64+
// forcibly enabled. This is the default behavior.
65+
"projects_path": "",
66+
67+
// Require Export
68+
//
69+
// When true: New projects will be created as letstry sessions.
70+
// These sessions will be automatically deleted once
71+
// the editor window is closed.
72+
//
73+
// When false: New projects will be stored in `projects_path`
74+
// and will be persisted after the editor window
75+
// is closed. No letstry session will be created.
76+
//
77+
// You can force `require_export` by passing `--temp` to `lt new`.
78+
"require_export": true,
79+
80+
// Default Editor
81+
//
82+
// The default editor to use for new sessions/projects.
83+
"default_editor": "vscode",
84+
85+
// Editors
86+
//
87+
// Available editors for new sessions/projects.
88+
"editors": [
89+
{
90+
"name": "vscode",
91+
"run_type": "run",
92+
"path": "C:\\Users\\natef\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe",
93+
"args": "-n",
94+
"process_capture_delay": 2000000000,
95+
"tracking_type": "file_access"
96+
}
97+
]
98+
}
99+
```
48100

49-
Creating a new session with letstry is simple and efficient. Use the `lt new` command to initialize a temporary project directory and open it in the default editor. This allows for quick prototyping. If you like the results, you can export the session to a more permanent location or save it as a template.
101+
### Creating a new Session or Project
102+
103+
Creating a new session or project with letstry is simple and efficient. Use the `lt new` command to initialize a new project or session and open it in the default editor.
50104

51105
```sh
52106
$ lt new
53107
```
54108

55-
If the VSCode window is closed, the temporary directory will be deleted. Therefore, you should either export your project using `lt export <path>` or save it as a template using `lt save <template-name>`.
109+
> [!IMPORTANT]
110+
> If `require_export` is enabled in your configuration or if you have not set a custom `projects_path`, when the VSCode window is closed the sessions temporary directory will be deleted. This is the default behavior for letstry. Therefore, you should either export your project using `lt export <path>` or save it as a template using `lt save <template-name>` (these commands must be run from within the sessions directory.)
56111
57112
Lets try sessions can be created from a directory path, a git repository URL, or a template name.
58113

@@ -124,31 +179,6 @@ To delete a template, use the `lt delete` command.
124179
$ lt delete <template-name>
125180
```
126181

127-
## Configuration
128-
129-
letstry can be configured using a configuration file. The configuration file is located at `~/.letstry/config.json`.
130-
131-
The config file allows you to specify different editors if you do not use VSCode.
132-
133-
**Windows Config Example**
134-
135-
`~/.letstry/config.json`
136-
```json
137-
{
138-
"default_editor": "vscode",
139-
"editors": [
140-
{
141-
"name": "vscode",
142-
"run_type": "run",
143-
"path": "C:\\Users\\natef\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe",
144-
"args": "-n",
145-
"process_capture_delay": 2000000000,
146-
"tracking_type": "file_access"
147-
}
148-
]
149-
}
150-
```
151-
152182
## Contributing
153183

154184
We welcome contributions to improve letstry. If you have suggestions or bug reports, please open an issue or submit a pull request.

internal/application/application.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func NewApplication(ctx context.Context) *Application {
6767

6868
hidden_commands.MonitorCommand(),
6969
general_commands.VersionCommand(),
70+
general_commands.PathCommand(),
7071
}
7172

7273
// Initialize the application.
@@ -79,8 +80,8 @@ func NewApplication(ctx context.Context) *Application {
7980
},
8081

8182
Name: cli.MainName(),
82-
ShortDescription: "a powerful tool for creating temporary workspaces",
83-
Description: cli.MainName() + " provides a temporary workspace for you to work in, and then destroys it when you are done.",
83+
ShortDescription: "a lightweight tool designed to give developers templated workspaces",
84+
Description: cli.MainName() + " is a lightweight yet powerful tool designed to give developers templated workspaces directly within their preferred IDE. Letting you spin up new projects quickly, save them as templates, and export them to a permanent location—all from your IDEs integrated terminal.",
8485
},
8586
}
8687

internal/application/commands/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func (c CommandName) String() string {
88

99
const (
1010
CommandVersion CommandName = "version"
11+
CommandPath CommandName = "path"
1112
CommandMonitor CommandName = "monitor"
1213
CommandClean CommandName = "clean"
1314
CommandPruneSessions CommandName = "prune"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package general
2+
3+
import (
4+
"context"
5+
6+
"github.com/letstrygo/letstry/internal/application/commands"
7+
"github.com/letstrygo/letstry/internal/cli"
8+
"github.com/letstrygo/letstry/internal/config"
9+
"github.com/letstrygo/letstry/internal/storage"
10+
)
11+
12+
func PathCommand() cli.Command {
13+
return cli.Command{
14+
Name: commands.CommandPath.String(),
15+
ShortDescription: "Displays paths relevant to LetsTry",
16+
Description: "Useful for locating your LetsTry config file, your LetsTry session cache file, or the directory in which LetsTry stores new sessions and projects.",
17+
Arguments: []cli.Argument{
18+
{
19+
Name: "file",
20+
Description: "Can be one of config, projects or sessions. Defaults to \"config\".",
21+
},
22+
},
23+
Executor: func(ctx context.Context, args []string) error {
24+
cfg, err := config.GetConfig()
25+
if err != nil {
26+
return err
27+
}
28+
29+
var opt string
30+
if len(args) > 0 {
31+
opt = args[0]
32+
}
33+
34+
switch opt {
35+
case "sessions":
36+
store := storage.GetStorage()
37+
sessPath := store.GetAbsolutePath("sessions.json")
38+
println(sessPath)
39+
return nil
40+
case "projects":
41+
path := cfg.LTPath
42+
if cfg.RequireExport {
43+
println("require-export enabled, all projects will be stored in a temporary directory and deleted once their corresponding session is terminated.")
44+
return nil
45+
}
46+
47+
if path == "" {
48+
println("project-path: custom projects_path not set, all projects will be stored in a temporary directory and deleted once their corresponding session is terminated.")
49+
return nil
50+
}
51+
52+
println(cfg.LTPath)
53+
return nil
54+
default:
55+
println(cfg.Path())
56+
return nil
57+
}
58+
},
59+
}
60+
}

internal/application/commands/sessions/cmd.new-session.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,31 @@ import (
1313
func NewSessionCommand() cli.Command {
1414
return cli.Command{
1515
Name: commands.CommandNewSession.String(),
16-
ShortDescription: "Create a new session",
17-
Description: "Create a new session using the specified source.",
16+
ShortDescription: "Create a new session or project",
17+
Description: "Create a new session or project using the specified source.",
1818
Arguments: []cli.Argument{
1919
{
2020
Name: "source",
21-
Description: "The source to use for the new session. Can be a git repository URL, a path to a directory, or the name of a letstry template.\n\nIf source is not provided, the session will be created from a blank source.",
21+
Description: "The source to use for the new session or project. Can be a git repository URL, a path to a directory, or the name of a letstry template.\n\nIf source is not provided, the session will be created from a blank source.",
22+
},
23+
{
24+
Name: "--temp",
25+
Description: "When set, session will be forcibly stored in a temporary location. This overrides the \"Require Export\" field in your config file.",
2226
},
2327
},
2428
Executor: func(ctx context.Context, args []string) error {
2529
var source string
30+
var forceRequireExport bool
2631

27-
if len(args) >= 1 {
32+
if len(args) > 0 {
2833
source = args[0]
2934
}
35+
if source == "--temp" {
36+
source = ""
37+
forceRequireExport = true
38+
} else if len(args) > 1 {
39+
forceRequireExport = args[1] == "--temp"
40+
}
3041

3142
mgr, err := manager.GetManager(ctx)
3243
if err != nil {
@@ -39,13 +50,18 @@ func NewSessionCommand() cli.Command {
3950
}
4051

4152
session, err := mgr.CreateSession(ctx, manager.CreateSessionArguments{
42-
Source: source,
53+
Source: source,
54+
ForceRequireExport: forceRequireExport,
4355
})
4456
if err != nil {
4557
return err
4658
}
4759

48-
logger.Printf("session created: %s\n", session.String())
60+
if session != nil {
61+
logger.Printf("session created: %s\n", session.String())
62+
} else {
63+
logger.Printf("project created")
64+
}
4965

5066
return nil
5167
},

internal/config/config.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,24 @@ import (
77
)
88

99
type Config struct {
10+
path string
11+
12+
// The path at which LT projects will be placed. Defaults to your systems
13+
// temporary directory.
14+
LTPath string `json:"projects_path"`
15+
// When enabled, projects created in letstry will be deleted after the
16+
// lt session is closed (i.e. when the editor is closed).
17+
//
18+
// You can override this by passing `--temp` when creating the LetsTry session.
19+
RequireExport bool `json:"require_export"`
20+
// The name of the default editor to use for new sessions. (Default: vscode)
1021
DefaultEditorName editors.EditorName `json:"default_editor"`
11-
AvailableEditors []editors.Editor `json:"editors"`
22+
// Editors available for use within LetsTry. (Default: vscode)
23+
AvailableEditors []editors.Editor `json:"editors"`
24+
}
25+
26+
func (cfg Config) Path() string {
27+
return cfg.path
1228
}
1329

1430
func (cfg Config) GetEditor(name string) (editors.Editor, error) {

internal/config/service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func GetConfig() (*Config, error) {
4343
return nil, fmt.Errorf("failed to decode config file: %v", err)
4444
}
4545

46+
config.path = store.GetAbsolutePath("config.json")
47+
4648
return config, nil
4749
}
4850

@@ -68,6 +70,7 @@ func getDefaultConfig() *Config {
6870
defaultEditor := editors.DefaultEditors()
6971

7072
return &Config{
73+
RequireExport: true,
7174
DefaultEditorName: defaultEditor[0].Name,
7275
AvailableEditors: editors.DefaultEditors(),
7376
}

0 commit comments

Comments
 (0)