cli

rust
use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about)]
struct Args {
    #[arg(short, long)]

clap for CLI argument parsing with derive macros

rust cli clap
by Marcus Chen 1 tab
rust
use anyhow::{Context, Result};
use std::fs;

fn load_config(path: &str) -> Result<String> {
    fs::read_to_string(path)
        .with_context(|| format!("failed to read config from {}", path))

anyhow::Context for adding error context without custom types

rust error-handling cli
by Marcus Chen 1 tab
rust
use std::process::Command;

fn main() -> std::io::Result<()> {
    let output = Command::new("ls")
        .arg("-la")
        .output()?;

std::process::Command for spawning external processes

rust processes cli
by Marcus Chen 1 tab
python
import csv
from django.core.management.base import BaseCommand, CommandError
from products.models import Product, Category


class Command(BaseCommand):

Django custom management command for data import

django python cli
by Priya Sharma 1 tab
php
<?php

namespace App\Console\Commands;

use App\Models\User;
use App\Notifications\NewsletterEmail;

Laravel custom Artisan commands

laravel artisan commands
by Carlos Mendez 2 tabs
rust
use std::collections::HashMap;

#[derive(Debug, PartialEq)]
pub enum LogLevel {
    Info,
    Warn,

Streaming Log File Aggregation With Buffered Line Iteration in Rust

rust streaming file-io
by codesnips 3 tabs
go
package appconfig

import (
	"flag"
	"io"
	"os"

Parsing and Validating CLI Flags into a Typed Config Struct in Go

cli flags configuration
by codesnips 3 tabs
python
from datetime import datetime

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

Register a Custom Flask CLI Command to Seed the Database with Faker

flask cli click
by codesnips 3 tabs
rust
use clap::{Args, Parser, Subcommand, ValueEnum};

#[derive(Parser, Debug)]
#[command(name = "tasks", version, about = "A tiny task manager")]
pub struct Cli {
    #[arg(short, long, global = true)]

Building a clap Subcommand Dispatcher With a Command Trait in Rust

rust clap cli
by codesnips 3 tabs
python
import errno
import fcntl
import os
import time

File-Based Locking to Prevent Concurrent Cron Job Runs in Python

locking concurrency fcntl
by codesnips 3 tabs
rust
use std::collections::HashMap;
use serde_json::Value;

#[derive(Debug)]
pub enum DispatchError {
    UnknownCommand(String),

Compile-Time Command Dispatch Table With a Rust Declarative Macro

rust macros dispatch
by codesnips 3 tabs
rust
const CONSECUTIVE_BONUS: f64 = 8.0;
const WORD_START_BONUS: f64 = 10.0;
const MATCH_BASE: f64 = 4.0;
const LEADING_PENALTY: f64 = 0.5;

#[derive(Debug, Clone, Copy)]

Fuzzy Search Ranker with Subsequence Matching and Score-Based Sorting in Rust

fuzzy-search ranking algorithms
by codesnips 3 tabs