Skip to content

Commit 1dc383e

Browse files
authored
feat: sort output of leetcode list by problem number (#98)
* chore: add devShell for contributors in flake.nix * feat: sort output of `leetcode list` by problem number
1 parent f53f5eb commit 1dc383e

File tree

4 files changed

+55
-83
lines changed

4 files changed

+55
-83
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
**/*.rs.bk
33
Cargo.lock
44
.DS_Store
5-
.idea
5+
.idea
6+
.direnv/

flake.lock

Lines changed: 6 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,40 @@
22
description = "Leet your code in command-line.";
33

44
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5-
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
65
inputs.utils.url = "github:numtide/flake-utils";
76

8-
outputs = { self, nixpkgs, rust-overlay, utils, ... }:
7+
outputs = { self, nixpkgs, utils, ... }:
98
utils.lib.eachDefaultSystem (system:
109
let
11-
pkgs = import nixpkgs { inherit system; overlays = [ rust-overlay.overlay ]; };
10+
pkgs = import nixpkgs { inherit system; };
11+
12+
nativeBuildInputs = with pkgs; [
13+
pkg-config
14+
];
15+
16+
buildInputs = with pkgs; [
17+
openssl
18+
dbus
19+
sqlite
20+
] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
1221

13-
platform = with pkgs; makeRustPlatform {
14-
rustc = rust-bin.nightly.latest.minimal;
15-
cargo = rust-bin.nightly.latest.minimal;
16-
};
17-
package = with pkgs; platform.buildRustPackage rec {
18-
pname = "leetcode-cli";
19-
version = "0.3.10";
2022

23+
package = with pkgs; rustPlatform.buildRustPackage rec {
24+
pname = "leetcode-cli";
25+
version = "0.3.11";
2126
src = fetchCrate {
2227
inherit pname version;
23-
sha256 = "SkJLA49AXNTpiWZByII2saYLyN3bAAJTlCvhamlOEXA=";
28+
sha256 = "sha256-DHtIhiRPRGuO6Rf1d9f8r0bMOHqAaJleUvYNyPiX6mc=";
2429
};
30+
cargoSha256 = "sha256-Suk/nQ+JcoD9HO9x1lYp+p4qx0DZ9dt0p5jPz0ZQB+k=";
2531

26-
cargoSha256 = "xhKF4qYOTdt8iCSPY5yT8tH3l54HdkOAIS2SBGzqsdo=";
32+
inherit buildInputs nativeBuildInputs;
2733

2834
# a nightly compiler is required unless we use this cheat code.
2935
RUSTC_BOOTSTRAP = 0;
3036

31-
# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-nightly";
32-
CFG_RELEASE_CHANNEL = "ngihtly";
33-
34-
nativeBuildInputs = [
35-
pkg-config
36-
rust-bin.stable.latest.default
37-
];
38-
39-
buildInputs = [
40-
openssl
41-
dbus
42-
sqlite
43-
] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
37+
# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
38+
CFG_RELEASE_CHANNEL = "stable";
4439

4540
meta = with pkgs.lib; {
4641
description = "Leet your code in command-line.";
@@ -54,6 +49,28 @@
5449
{
5550
defaultPackage = package;
5651
overlay = final: prev: { leetcode-cli = package; };
52+
53+
devShell = with pkgs; mkShell {
54+
name = "shell";
55+
inherit nativeBuildInputs;
56+
57+
buildInputs = buildInputs ++ [
58+
rustc
59+
cargo
60+
rustfmt
61+
clippy
62+
rust-analyzer
63+
cargo-edit
64+
cargo-bloat
65+
cargo-audit
66+
cargo-about
67+
cargo-outdated
68+
];
69+
70+
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
71+
RUST_BACKTRACE = "full";
72+
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
73+
};
5774
}
5875
);
5976
}

src/cmds/list.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ impl Command for ListCommand {
189189
ps.retain(|x| x.name.to_lowercase().contains(&lowercase_kw));
190190
}
191191

192+
// output problem lines sorted by [problem number] like
193+
// [ 1 ] Two Sum
194+
// [ 2 ] Add Two Numbers
195+
ps.sort_unstable_by_key(|p| p.fid);
196+
192197
let out: Vec<String> = ps.iter().map(ToString::to_string).collect();
193198
println!("{}", out.join("\n"));
194199

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy