Skip to content

Commit 928d380

Browse files
committed
feat: base directory logic
- finds git root and uses that as base dir - prefers current directory for manifest search - hopefully improved how some imports are done - fix how manifest auto-selection failure is handled - fix docs and cargo.toml
1 parent 7e91fc3 commit 928d380

File tree

7 files changed

+338
-170
lines changed

7 files changed

+338
-170
lines changed

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
[package]
22
name = "flatplay"
33
version = "0.1.0"
4+
authors = ["Mufeed Ali <me@mufeed.dev>"]
5+
description = "Simple CLI tool to build and run Flatpak applications."
6+
readme = "README.md"
7+
license = "MIT"
48
edition = "2024"
9+
homepage = "https://github.com/mufeedali/flatplay"
10+
repository = "https://github.com/mufeedali/flatplay"
11+
keywords = ["flatpak", "cli", "gnome"]
12+
categories = ["command-line-utilities"]
513

614
[dependencies]
715
clap = { version = "4.5.41", features = ["derive"] }

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# Flatplay
22

3-
Early days.
3+
Flatplay is a simple CLI tool to build and run Flatpak applications. It's designed to be easy to integrate into your workflows with editors like Zed or neovim.
4+
5+
Note that this is a **work in progress** and you might encounter issues along the way.
6+
7+
## External Dependencies
8+
9+
Flatplay relies on the following external commands to be available on your system:
10+
11+
- `git`
12+
- `gdbus`
13+
- `flatpak`
14+
- `flatpak-builder`
15+
16+
## Installation & Usage
417

518
```bash
619
# Install into ~/.local/bin (or XDG_BIN_HOME)
@@ -57,7 +70,7 @@ Add the following tasks to your `tasks.json` file (you can open it with the `zed
5770
}
5871
```
5972

60-
Next, add new bindings to your `keymaps.json` file (you can open it with the `zed: open keypam` action):
73+
Next, add new bindings to your `keymaps.json` file (you can open it with the `zed: open keymap` action):
6174

6275
```json
6376
{
@@ -74,7 +87,7 @@ Then you can run any of the tasks by pressing `Alt-Shift-T`, or use `Ctrl-Alt-B`
7487

7588
# Some notes
7689

77-
- A lot of the code is almost directly borrowed from [`flatpak-vscode`](https://github.com/bilelmoussaoui/flatpak-vscode).
78-
- Not all features are properly implemented yet. The focus so far has been just on getting something working to conveniently work on [Wordbook](https://github.com/mufeedali/Wordbook) while using anything that's not VS Code.
79-
- I hope to improve it over time and I hope Bilal forgives me for the sins I've committed here.
90+
- A lot of the logic is borrowed from [`flatpak-vscode`](https://github.com/bilelmoussaoui/flatpak-vscode).
91+
- There will be bugs and missing features. Please report them, or better yet, send a PR.
8092
- I'm not a Rust programmer.
93+
- I hope to improve it over time and I hope Bilal forgives me for the sins I've committed here.

src/command.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use std::process::{Command, Stdio};
2+
13
use anyhow::Result;
24
use colored::*;
3-
use std::process::{Command, Stdio};
45

56
// Returns true if running inside a Flatpak sandbox.
67
fn is_sandboxed() -> bool {
@@ -23,7 +24,11 @@ fn command_succeeds(cmd: &str, args: &[&str]) -> bool {
2324
}
2425

2526
// Runs a command, handling Flatpak sandbox and container specifics.
26-
pub fn run_command(command: &str, args: &[&str]) -> Result<()> {
27+
pub fn run_command(
28+
command: &str,
29+
args: &[&str],
30+
working_dir: Option<&std::path::Path>,
31+
) -> Result<()> {
2732
let mut command_args = args.to_vec();
2833

2934
// Workaround for rofiles-fuse issues in containers.
@@ -59,11 +64,14 @@ pub fn run_command(command: &str, args: &[&str]) -> Result<()> {
5964
program.italic(),
6065
final_args.join(" ").italic()
6166
);
62-
let mut command_process = Command::new(program)
63-
.args(&final_args)
67+
let mut cmd = Command::new(program);
68+
cmd.args(&final_args)
6469
.stdout(Stdio::inherit())
65-
.stderr(Stdio::inherit())
66-
.spawn()?;
70+
.stderr(Stdio::inherit());
71+
if let Some(dir) = working_dir {
72+
cmd.current_dir(dir);
73+
}
74+
let mut command_process = cmd.spawn()?;
6775

6876
let status = command_process.wait()?;
6977

@@ -78,13 +86,13 @@ pub fn run_command(command: &str, args: &[&str]) -> Result<()> {
7886
}
7987

8088
// Runs flatpak-builder, preferring the native binary, then the Flatpak app.
81-
pub fn flatpak_builder(args: &[&str]) -> Result<()> {
89+
pub fn flatpak_builder(args: &[&str], working_dir: Option<&std::path::Path>) -> Result<()> {
8290
if command_succeeds("flatpak-builder", &["--version"]) {
83-
run_command("flatpak-builder", args)
91+
run_command("flatpak-builder", args, working_dir)
8492
} else if command_succeeds("flatpak", &["run", "org.flatpak.Builder", "--version"]) {
8593
let mut new_args = vec!["run", "org.flatpak.Builder"];
8694
new_args.extend_from_slice(args);
87-
run_command("flatpak", &new_args)
95+
run_command("flatpak", &new_args, working_dir)
8896
} else {
8997
Err(anyhow::anyhow!(
9098
"Flatpak builder not found. Please install either `flatpak-builder` from your distro repositories or `org.flatpak.Builder` through `flatpak install`."

0 commit comments

Comments
 (0)